I have created a script report and one of the export format is xml. I would like to save the xml file on a hard disk.
Currently, after export, the xml is displayed in another tab of a web browser (Firefox).
How to make it saved as file?
to return the report results, right?
Try replacing this with
return new CompiledXmlReport(writer.toString()){
@Override
public String getMimeType() {
return "application/octet-stream";
}
}
what happens here is that we override the correct mimetype (which is what the browser uses to decide how to handle a file) with something generic. So the browser no longer knows that the dowloaded file is a xml file and does not try to display it. It’s kind of a hack (the correct approach would be to set a Content-disposition header, but you cant do this from a scriptreport (yet)), but it should do it.