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: