Im trying to return a File as a response from the server in order to be download from the client.
Im not sure what am i doing wrong i followed some examples but i still cant download the file, please assume that the file is already stored in the directory.
Here is my code:
@RequestMapping(value="/reports/downloadCsv", method=RequestMethod.POST)
public void saveToCsv(
@Validated HttpServletRequest request,
@Validated HttpSession session,
@Validated HttpServletResponse response,
@RequestParam String report) {
InputStream in = new FileInputStream("C:\\server\\reports\\AccessReport.csv");
response.setContentType("text/csv;charset=utf-8");
response.setHeader("Content-disposition", "attachment; filename=AccessReport.csv");
FileCopyUtils.copy(in, response.getOutputStream());
response.flushBuffer();
}
And this is my ajax call:
$.ajax({
url: "/server/reports/downloadCsv",
type: "post",
data: {
report: "AccessReport.csv"
},
type: 'POST',
success: function(res){
}
});