How to set ‘Content-Disposition’ and ‘Filename’ when using FileSystemResource to force a file download file?

In addition to the accepted answer, Spring has the class ContentDisposition specific for this purpose. I believe it deals with the file name sanitization. ContentDisposition contentDisposition = ContentDisposition.builder(“inline”) .filename(“Filename”) .build(); HttpHeaders headers = new HttpHeaders(); headers.setContentDisposition(contentDisposition);

How to get file name from content-disposition

Here is how I used it sometime back. I’m assuming you are providing the attachment as a server response. I set the response header like this from my REST service response.setHeader(“Content-Disposition”, “attachment;filename=XYZ.csv”); function(response, status, xhr){ var filename = “”; var disposition = xhr.getResponseHeader(‘Content-Disposition’); if (disposition && disposition.indexOf(‘attachment’) !== -1) { var filenameRegex = /filename[^;=\n]*=(([‘”]).*?\2|[^;\n]*)/; var … Read more

Uses of content-disposition in an HTTP response header

Note that RFC 6266 supersedes the RFCs referenced below. Section 7 outlines some of the related security concerns. The authority on the content-disposition header is RFC 1806 and RFC 2183. People have also devised content-disposition hacking. It is important to note that the content-disposition header is not part of the HTTP 1.1 standard. The HTTP … Read more