0
我有和API链接自动开始下载文件,如果我在地址栏中按照它。我们称之为my-third-party-download-link-com。Express res.redirect显示内容但不下载
但是,在Express框架中,我设置res.redirect(my-third-party-downloading-link-com)。我得到状态代码301,并可以在开发人员工具中看到预览标签中的文件内容。但是我无法让浏览器下载这个文件。
我适当的请求处理程序如下:
downloadFeed(req, res) {
const { jobId, platform, fileName } = req.query;
const host = platform === 'production' ? configs.prodHost :
configs.stageHost;
const downloadLink = `${host}/api/v1/feedfile/${jobId}`;
// I also tried with these headers
// res.setHeader('Content-disposition', 'attachment;
// filename=${fileName}.gz');
// res.setHeader('Content-Type', 'application/x-gzip');
res.redirect(downloadLink)
}
PS现在,为了解决这个问题,我建立我的第三方的下载链接-COM在后端,发送与res.end然后:
window.open(**my-third-party-downloading-link-com**, '_blank').
但我不喜欢这个解决方案。我该如何告诉浏览器开始从这个第三方API下载内容?
你是不对的。我们正在谈论第三方链接,而不是关于服务器文件系统上的文件。 –
好的,那么你可以检查这个问题,这可能会有所帮助https://stackoverflow.com/questions/26288055/how-to-send-a-file-from-remote-url-as-a-get-response -in节点-JS-EXPRESS-应用 –