요르딩딩

[Spring 분석] HTTP multipart 본문

[Web]/[Spring]

[Spring 분석] HTTP multipart

요르딩딩 2021. 4. 6. 17:57
728x90
HTTP Multipart

: HTTP를 통해 File을 SERVER로 전송하기 위해 사용되는 Content-type입니다

.

간단하게 HTTP(request와 response 둘 다)는 4개로 나눌 수 있습니다.

  1. Request line
  2. HTTP Header
  3. Empty line
  4. Message body

여기서 Message body에 들어가는 데이터 타입을 HTTP Header에 명시해줄 수 있는데, 명시할 수 있도록 해주는 필드가 바로 Content-type입니다.

그리고 바로 이 Content-type 필드에 MIME 타입을 기술해줄 수 있는데 여러 MIME 타입 중 하나가 바로 Multipart입니다.

Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x

Content-Disposition: form-data; name="submit-name"
Sally
--AaB03x

Content-Disposition: form-data; name="files"; filename="essayfile.txt" Content-Type: text/plain
...contents of _essayfile.txt_...
--AaB03x--

 

[사용상황]

HTML에서 파일을 업로드할때 Content-Type: multipart/form-data 형식으로 주면 백엔드에서 File을 받을 수 있습니다.

백엔드에서는 MultipartHTTPRequest 객체를 통해 해당을 꺼내서 사용할 수 있습니다.(getFile() 메소드 사용 )

728x90
Comments