I have some xml files stored as strings in my database and scala+spring based backend with this controller:
@RequestMapping(value = Array("/download"), method = Array(RequestMethod.GET))
def downloadFile(@RequestParam filename: String, //some more params
response: HttpServletResponse) = {
val fileContent = // some logic here, returns file content as String
response.setContentType("application/xml")
response.setHeader("Content-Disposition", s"attachment;filename=$filename")
response.setStatus(HttpServletResponse.SC_OK)
response.getOutputStream.write(fileContent.getBytes)
response.flushBuffer()
}
Also i have this script:
$.ajax({
type: "GET",
url: url,
data: {
filename: filename //and some more params
}
})
Then i send HTTP request to server, get right HTTP response and then nothing happens. All info i have from browser logs is that response has file content in body and headers, but download never starts.
What am i doing wrong?
I saw these SO Q&A but they didnt help me at all:
UPD1: Also tried this one, with no result.