在nodejs上,我正在按以下方式发送文件:
res.sendFile(fileName,{ root: path.join(__dirname, '../') });
在做出反应时,我一直试图用axios将文件下载成功,但没有成功:
let dowloadGet = async (url, auth) =>
await axiosDownload.get(url, { headers: { 'Authorization': `Bearer ${auth}` }, responseType: 'blob' });
let response = await API.get(`${this.state.BE_route}/download_script_bytest/${this.props.test._id}`, this.props.idToken)
const url = window.URL.createObjectURL(new Blob([response.data], {type:'application/zip'}));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.zip');
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);