【发布时间】:2021-08-14 18:51:24
【问题描述】:
大家好,我正在尝试创建一个功能,允许用户输入文件路径并下载它。我正在使用输入文本类型的表单来获取路径。我正在使用 Node.js 和 Express 路由器来处理获取和发布请求。由于某种原因,我的 res.download 无法正常工作。
router.get('/downloadFiles', (req, res, next) => {
const filePath = req.query.filePath;
res.download(filePath);
res.redirect('/');
});
【问题讨论】:
-
你检查过路径上的文件是否存在,路径是否正确?
-
Console.log(filePath) 并检查资源是否确实存在。
-
另外,res.download() 之后的 res.redirect() 不应该工作。您没有收到标头已发送错误吗?
标签: node.js rest express https