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

后端 未结 5 635
囚心锁ツ
囚心锁ツ 2020-12-13 17:52

What is the most appropriate, and standard, way to set the Content-Disposition=attachment and filename=xyz.zip using Spring 3 FileSystemResou

5条回答
  •  暖寄归人
    2020-12-13 18:16

    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);
    

提交回复
热议问题