Reputation: 181
I've got a request from VueJS frontend to my backend server:
let config = {header : {'Content-Type' : 'multipart/form-data'}};
const res = await axios.patch(`http://0.0.0.0:8080/report/${this.docGuid}`, data, config);
Response headers:
HTTP/1.1 200 OK
date: Tue, 30 Mar 2021 13:05:00 GMT
server: uvicorn
content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
content-disposition: attachment; filename*=utf-8''IL-NS-0_LSM.docx
content-length: 600357
last-modified: Tue, 30 Mar 2021 13:05:01 GMT
etag: c1a4f72bf0ad07234099ac6cec97e635
Request headers:
PATCH /report/cb07f12a7a49435e8e0f306e71c01969 HTTP/1.1
Host: 0.0.0.0:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Accept: application/json, text/plain, */*
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------129404071228287858071180535042
Content-Length: 95039
Connection: keep-alive
which is creating a MS docx file on server side and reverted this created file in response. I try to download it:
let blob = new Blob([res.data], {type: res.headers["content-type"]});
window.open(URL.createObjectURL(blob));
And it works, except dowloaded file is corrupted and I cannot open it. Besides serverside copy is fine and openable.
MIME type set as "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
What could be wrong? Thanks in advance)
Upvotes: 0
Views: 901
Reputation: 181
I finally found out that there should be responseType
parametr set as blob
.
So:
config = {header : {'Content-Type' : 'multipart/form-data'}, responseType: 'blob'};
Upvotes: 2