How to download files supported by reactjs and nodejs

getuploadedfiles(employeeDetails) { return axios({ url:process.env.API_HOST+'/getuploadedfiles', method:'get', headers:{ 'Content-Type': 'multipart/form-data', withCredentials:true, }, responseType:'arraybuffer', // try to add this line params:{ employeeDetails } }) .then(async response => { console.log("response status is ss"); console.log(response.status); if(response.status === 401) { console.log("notValidUser"); return response.data; } else { console.log("got al files in api "); console.log("type of response isss "+typeof(response)); //let blob = await new Blob([response.data], { type: 'application/zip' }) // console.log("blob iss "); //console.log(blob); download(response.data,"attachement.zip","application/zip") // filename with extenstion "attachment.zip" file content "application/zip" you can set it dynamically // let link = document.createElement('a') // link.href = window.URL.createObjectURL(blob) // link.download = 'attachement.zip' // link.click() return response.data; } }) .catch(err=>{ console.log(err); }) },

Guess you like

Origin www.cnblogs.com/gamecenter/p/11331800.html