Open DolphaGo opened 3 years ago
formData에 분명히 file을 append 했음에도, log를 찍어보면, 아무것도 보이지 않는다?
https://stackoverflow.com/questions/37235810/formdata-object-shows-empty-even-after-calling-append
fetchRequest 난이도가 개 헬임. 진짜. 모든걸 커스텀해서 처리하니까 정신 나갈뻔함. 시간도둑 그자체. 특히 multipart fetchRequest -> axios로 바꾸니, 한 방에 해결됐는데, axios로는 브라우저 상에서 다운로드를 못받는다는, 즉, Streaming Data를 받지 못한다는 글이 있어서, 오우씨 뭐야 하고 읽어봤다. https://stackoverflow.com/questions/58609130/how-to-consume-the-download-stream-from-axios-using-streamsaver-js
근데, 뭐 해결할 수 있음. responseType으로 blob
이라는 값을 주면 된다.
가장 처음의 Exception은
the request was rejected because no multipart boundary was found
였다. 이 때는 요청을 보낼 때multipart/form-data
를 직접 지정해서 요청을 보냈었다.구글링해보니 대부분이 요청을 보낼 때 직접 header를 세팅하지 말라는 것이였다. 그래서 다음과 같이 헤더 설정을 뺀 채로 reuqest를 보내봤다.
그리고 서버쪽은 다음과 같다.
그랬더니 등장한 에러
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
성공할 때 (Swagger)
실패할 때(Vue)
Content-Type: multipart/form-data; boundary~~ 이렇게 나와야 하는데 말이다.
해결했다. new FormData() 로 하면 된다.