Zip File downloaded from ReactJs/Axios is corruptedDownload multiple files as a zip-file using phpdownloaded zip file corruptedBitBucket - download source as ZIPDownloaded zip file is corruptedHow to download files using axiosFileSaver downloading corrupted ZIP fileDownload an epub file through axios & react-file-download lbraries in reactjsUnable to download zip file using axiosDownload and zip files in React?Download zip files using axios

Cause of continuous spectral lines

What are the words for people who cause trouble believing they know better?

How many times can you cast a card exiled by Release to the Wind?

How is it possible that Gollum speaks Westron?

Avoiding cliches when writing gods

What's up with this leaf?

What can cause the front wheel to lock up when going over a small bump?

How did students remember what to practise between lessons without any sheet music?

When conversion from Integer to Single may lose precision

Orange material in grout lines - need help to identify

Select items in a list that contain criteria #2

How to translate “Me doing X” like in online posts?

Strange symbol for two functions

siunitx error: Invalid numerical input

Is it possible to (7 day) schedule sleep time of a hard drive?

Implement Homestuck's Catenative Doomsday Dice Cascader

Are "living" organ banks practical?

Turing patterns

Does there exist a word to express a male who behaves as a female?

How bad would a partial hash leak be, realistically?

Does an ice chest packed full of frozen food need ice?

How to generate random points without duplication?

Question about JavaScript Math.random() and basic logic

Building a road to escape Earth's gravity by making a pyramid on Antartica



Zip File downloaded from ReactJs/Axios is corrupted


Download multiple files as a zip-file using phpdownloaded zip file corruptedBitBucket - download source as ZIPDownloaded zip file is corruptedHow to download files using axiosFileSaver downloading corrupted ZIP fileDownload an epub file through axios & react-file-download lbraries in reactjsUnable to download zip file using axiosDownload and zip files in React?Download zip files using axios






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















I'm trying to download a zip file from a Django api and have the user download it. There are two .csv files in the zip.



I am able to download a single .csv files individually, but when I try to download the zip and unzip, I get errors that the zip is corrupted. For sanity check, I am able to send the request via Postman. I am able to successfully download and unzip the file using that.



Here is my code fragment:



 axios
.post('http://0.0.0.0:8000/sheets/', data,

headers:
'Content-Type': 'multipart/form-data',
'responseType': 'arraybuffer'

)
.then(res => {
console.log(res.data)
const disposition = res.request.getResponseHeader('Content-Disposition')
var fileName = "";
var filenameRegex = /filename[^;=n]*=((['"]).*?2|[^;n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1])
fileName = matches[1].replace(/['"]/g, '');

let blob = new Blob([res.data], type: 'application/zip' )

const downloadUrl = URL.createObjectURL(blob)
let a = document.createElement("a");
a.href = downloadUrl;
a.download = fileName;
document.body.appendChild(a);
a.click();









share|improve this question






















  • Did you find a solution? I'm struggling with the same issue :(

    – Tomer
    Mar 24 at 11:55











  • Posted the answer below!

    – btbam91
    Mar 24 at 15:31











  • The file shows corrupted in my case, without the headers also. Am executing the same code as above. Does anyone solved the issue? Any lead will be helpful.

    – Vishnu
    Apr 2 at 18:31

















3















I'm trying to download a zip file from a Django api and have the user download it. There are two .csv files in the zip.



I am able to download a single .csv files individually, but when I try to download the zip and unzip, I get errors that the zip is corrupted. For sanity check, I am able to send the request via Postman. I am able to successfully download and unzip the file using that.



Here is my code fragment:



 axios
.post('http://0.0.0.0:8000/sheets/', data,

headers:
'Content-Type': 'multipart/form-data',
'responseType': 'arraybuffer'

)
.then(res => {
console.log(res.data)
const disposition = res.request.getResponseHeader('Content-Disposition')
var fileName = "";
var filenameRegex = /filename[^;=n]*=((['"]).*?2|[^;n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1])
fileName = matches[1].replace(/['"]/g, '');

let blob = new Blob([res.data], type: 'application/zip' )

const downloadUrl = URL.createObjectURL(blob)
let a = document.createElement("a");
a.href = downloadUrl;
a.download = fileName;
document.body.appendChild(a);
a.click();









share|improve this question






















  • Did you find a solution? I'm struggling with the same issue :(

    – Tomer
    Mar 24 at 11:55











  • Posted the answer below!

    – btbam91
    Mar 24 at 15:31











  • The file shows corrupted in my case, without the headers also. Am executing the same code as above. Does anyone solved the issue? Any lead will be helpful.

    – Vishnu
    Apr 2 at 18:31













3












3








3








I'm trying to download a zip file from a Django api and have the user download it. There are two .csv files in the zip.



I am able to download a single .csv files individually, but when I try to download the zip and unzip, I get errors that the zip is corrupted. For sanity check, I am able to send the request via Postman. I am able to successfully download and unzip the file using that.



Here is my code fragment:



 axios
.post('http://0.0.0.0:8000/sheets/', data,

headers:
'Content-Type': 'multipart/form-data',
'responseType': 'arraybuffer'

)
.then(res => {
console.log(res.data)
const disposition = res.request.getResponseHeader('Content-Disposition')
var fileName = "";
var filenameRegex = /filename[^;=n]*=((['"]).*?2|[^;n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1])
fileName = matches[1].replace(/['"]/g, '');

let blob = new Blob([res.data], type: 'application/zip' )

const downloadUrl = URL.createObjectURL(blob)
let a = document.createElement("a");
a.href = downloadUrl;
a.download = fileName;
document.body.appendChild(a);
a.click();









share|improve this question














I'm trying to download a zip file from a Django api and have the user download it. There are two .csv files in the zip.



I am able to download a single .csv files individually, but when I try to download the zip and unzip, I get errors that the zip is corrupted. For sanity check, I am able to send the request via Postman. I am able to successfully download and unzip the file using that.



Here is my code fragment:



 axios
.post('http://0.0.0.0:8000/sheets/', data,

headers:
'Content-Type': 'multipart/form-data',
'responseType': 'arraybuffer'

)
.then(res => {
console.log(res.data)
const disposition = res.request.getResponseHeader('Content-Disposition')
var fileName = "";
var filenameRegex = /filename[^;=n]*=((['"]).*?2|[^;n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1])
fileName = matches[1].replace(/['"]/g, '');

let blob = new Blob([res.data], type: 'application/zip' )

const downloadUrl = URL.createObjectURL(blob)
let a = document.createElement("a");
a.href = downloadUrl;
a.download = fileName;
document.body.appendChild(a);
a.click();






django reactjs zip axios zipfile






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 29 at 4:53









btbam91btbam91

67211




67211












  • Did you find a solution? I'm struggling with the same issue :(

    – Tomer
    Mar 24 at 11:55











  • Posted the answer below!

    – btbam91
    Mar 24 at 15:31











  • The file shows corrupted in my case, without the headers also. Am executing the same code as above. Does anyone solved the issue? Any lead will be helpful.

    – Vishnu
    Apr 2 at 18:31

















  • Did you find a solution? I'm struggling with the same issue :(

    – Tomer
    Mar 24 at 11:55











  • Posted the answer below!

    – btbam91
    Mar 24 at 15:31











  • The file shows corrupted in my case, without the headers also. Am executing the same code as above. Does anyone solved the issue? Any lead will be helpful.

    – Vishnu
    Apr 2 at 18:31
















Did you find a solution? I'm struggling with the same issue :(

– Tomer
Mar 24 at 11:55





Did you find a solution? I'm struggling with the same issue :(

– Tomer
Mar 24 at 11:55













Posted the answer below!

– btbam91
Mar 24 at 15:31





Posted the answer below!

– btbam91
Mar 24 at 15:31













The file shows corrupted in my case, without the headers also. Am executing the same code as above. Does anyone solved the issue? Any lead will be helpful.

– Vishnu
Apr 2 at 18:31





The file shows corrupted in my case, without the headers also. Am executing the same code as above. Does anyone solved the issue? Any lead will be helpful.

– Vishnu
Apr 2 at 18:31












1 Answer
1






active

oldest

votes


















0














The problem was that 'responseType': 'arraybuffer' should not be in "headers."






share|improve this answer























  • Then where should it be?

    – Tomer
    Mar 25 at 10:42











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54414054%2fzip-file-downloaded-from-reactjs-axios-is-corrupted%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The problem was that 'responseType': 'arraybuffer' should not be in "headers."






share|improve this answer























  • Then where should it be?

    – Tomer
    Mar 25 at 10:42















0














The problem was that 'responseType': 'arraybuffer' should not be in "headers."






share|improve this answer























  • Then where should it be?

    – Tomer
    Mar 25 at 10:42













0












0








0







The problem was that 'responseType': 'arraybuffer' should not be in "headers."






share|improve this answer













The problem was that 'responseType': 'arraybuffer' should not be in "headers."







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 15:30









btbam91btbam91

67211




67211












  • Then where should it be?

    – Tomer
    Mar 25 at 10:42

















  • Then where should it be?

    – Tomer
    Mar 25 at 10:42
















Then where should it be?

– Tomer
Mar 25 at 10:42





Then where should it be?

– Tomer
Mar 25 at 10:42



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54414054%2fzip-file-downloaded-from-reactjs-axios-is-corrupted%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh