-1

I'm trying to get a download to open from a call to another function that returns it as a ResponseEntity Byte. The problem is that when it returns it isn't downloading in the browser. A download box will open when I query the function I'm calling directly.

byte[] content = ...//gets the content
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.parseMediaType("application/pdf"));

return new ResponseEntity<byte[]>(contents, header, HttpStatus.OK);

why isn't a download box coming up in the browser when I call this from the javascript? am I missing something?

Nickknack
  • 827
  • 4
  • 12
  • 26

1 Answers1

-1

please include the following header to the response which instruct the browser to download the file

Response.AddHeader("content-disposition", "attachment;filename=<yourfilename>.pdf");

Substitute a friend filename in the in the above code to default the filename.

  • This didn't work for me. I tried: header.add("content-disposition", "attachment;filename=test.pdf"); I also tried: header.setContentDispositionFormData("file.pdf", "file.pdf"); – Nickknack Feb 17 '17 at 20:17