下载对话框不显示 [英] download dialog not displaying
本文介绍了下载对话框不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法为我的生活提供一个下载对话框来弹出,而不是直接在我的节点应用程序中下载文件。
我的烦恼的代码看起来像这样:
app.get(`/ search / download`,function(req,res){
pre>
var request = require(`request`);
请求({uri:`http:// some.csv.file`,headers:{`content-type`:`text / csv`}}
,function(err,response,body){
res.set(`Content-Disposition`,`attachment; filename =search-results.csv`);
res.set (`Content-Type`,`text / csv`);
res.send(body);
});
}
无论我改变什么,Chrome和Safari都会立即下载文件,而不是打开一个保存对话框。
解决方案将内容类型从
text / csv
更改为application / octet-stream
。
app.get(`/ search / download`,function(req,re s){
var request = require(`request`);
请求({uri:`http:// some.csv.file`,headers:{`content-type`:`text / csv`}}
,function(err,response,body) {
res.set(`Content-Disposition`,`attachment; filename =search-results.csv`);
res.set(`Content-Type`,`application / octet-stream`);
res.send(body);
});
}
I can't for the life of me get a download dialog to pop up instead of just directly downloading a file in my node application.
My troubled code looks like this:
app.get(`/search/download`, function(req, res){ var request = require(`request`); request({uri: `http://some.csv.file`, headers: {`content-type`: `text/csv`}} , function(err, response, body) { res.set(`Content-Disposition`, `attachment; filename="search-results.csv"`); res.set(`Content-Type`, `text/csv`); res.send(body); }); }
No matter what I change, both Chrome and Safari immediately download the file instead of bringing up a save dialog box.
解决方案Change the Content-Type from
text/csv
toapplication/octet-stream
.app.get(`/search/download`, function(req, res){ var request = require(`request`); request({uri: `http://some.csv.file`, headers: {`content-type`: `text/csv`}} , function(err, response, body) { res.set(`Content-Disposition`, `attachment; filename="search-results.csv"`); res.set(`Content-Type`, `application/octet-stream`); res.send(body); }); }
这篇关于下载对话框不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文