I need to send JSON to a web service using HTTP POST method in AngularJS to download a file.
AngularJS:-
$http
.post(
'url',
'My Json data ')
.success(function(response) {
console.log('file downloading');
})
.error(
function(response) {
console
.log('Error while downloading file');
});
Spring Controller:-
@RequestMapping(value = "/url", method = RequestMethod.POST)
@ResponseBody
public void getfile(@RequestBody List<ABC> abc, HttpServletResponse response)
throws JRException, IOException, SQLException {
//My code here
response.reset();
response.setContentType("application/x-pdf");
response.setHeader("Content-disposition", "attachment; filename=ABC.pdf");
final OutputStream outStream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint,outStream);
outStream.flush();
outStream.close();
I have to call this from angular using POST request. How to acheive so?
EDIT I was able to meet the requirements by referring this thread.