We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Zip file corrupted when downloading in React and NodeJs

I have an application in React and NodeJS. React makes a post to node with an id and node makes a get to an api. The file gets downloaded it shows 14kb so it contains something but when I try to open it says corrupted.

Here is the React function that makes the download:


iaId2() {
var id = document.getElementById("id_desc").value;
console.log(id);
const article = { id_trimis:id}
axios({url:"http://localhost:3001/descarcare", data:article, method:"POST", 
responseType: 'blob',
}).then((response) => {
  const url = window.URL.createObjectURL(new Blob([response.data]));
  const link = document.createElement('a');
  link.rel='nofollow' href = url;
  link.setAttribute('download', 'file.rar'); 
  document.body.appendChild(link);
  link.click();
});

}


Here is the NodeJS function: 


app.post('/descarcare', function(req, res) {
req.header("Content-Type", "application/octet-stream");
var id = req.body.id_trimis;
console.log(id);
axios.get('http://111.222.333:555/prod/aaa/rest/descarcare? 
id='+id).then((response) => {
console.log(response.data);  
console.log("Trimis");
res.send(response.data);



Like I said it downloads in the browser a zip file that contains 14kb but when I try to open it, it says corrupted.

Thanks in advance


Here is the stackoverflow link if you want to reply there. Thanks:





1 Reply

KR Keerthana Rajendran Syncfusion Team September 30, 2021 07:44 AM UTC

Hi Serban, 

Thanks for contacting Syncfusion support. 

Based on the component chosen (File Manager), we have ensured the download functionality in React File Manager with Node JS File provider which is working fine.  

Please ensure this from your end with the below demo link.  



We also suspect that your query is related to general download operation in React and if so, we request you to follow the below blogs for general queries. 




Please get back to us if you have any queries with Syncfusion components

Regards, 
Keerthana R. 


Loader.
Up arrow icon