我有一条这样的路线:
exports.downloadFile = app => {
app.get('/install/download', (request, result) => {
result.download(`${__dirname}../../../public/exec/install.exe`, error => {
if (error) console.log("[FAILURE][RESOURCE] Could not download installation file\r\n");
else console.log("[SUCCESS][RESOURCE] Installation file has been downloaded\r\n");
});
});
}通过这种方式,我试图让它在我点击一个按钮时,这个文件就会被下载。当我点击按钮时,我会收到一条成功的消息,但我的浏览器没有任何下载的指示,也没有提示我做任何事情。我是否需要添加一些额外的组件来确保它正常工作?
这是在我的客户端执行抓取操作的代码:
const downloadFile = () => {
const url = `${window.location.protocol}//${window.location.host}/install/download`;
fetch(url)
.catch(error => alertMessage(error.message));
}我假设这可能与我没有.then来处理获取有关,但我不确定我应该在那里添加什么,我从文档中得到的印象是浏览器会自动处理这一部分?
发布于 2020-09-14 13:50:01
您忘记传递一个下载名称参数。请按如下方式修改下载函数。
result.download(`${__dirname}../../../public/exec/install.exe`, 'install.exe', error => {
if (error) console.log("[FAILURE][RESOURCE] Could not download installation file\r\n");
else console.log("[SUCCESS][RESOURCE] Installation file has been downloaded\r\n");
});https://stackoverflow.com/questions/63878190
复制相似问题