Spring

Spring - MVC FileDownload

엔꾸꾸 2019. 7. 30. 22:03

Spring - FileDownload

  • FileResource를 읽어오는 방법

    • Spring ResourceLoader
  • FileDownload시 응답 헤더

    • Content-Dispoistion: 사용자가 해당 파일을 다운로드시 사용할 파일명
    • Content-Type: 파일의 타입
    • Content-Length: 파일의 크기
  • Apache-Tika

    • 파일의 타입 (MediaType)

  • ResponseEntity

    • 응답 상태코드
    • 응답 헤더
    • 응답 본문
  • FileDownload

    • ResourceLoader를 사용해서 fileName에 해당하는 Resource를 읽어온다.
    • resource에서 얻은 File객체를 Tika 를 활용하여 해당 파일의 Type 정보를 취득
    • ResponseEntity의 응답헤더로 CONTENT_DISPOSITION, CONTENT_TYPE, CONTENT_LENGTH 정보와 본문으로 resource를 응답한다.