我有一个签名的Amazon S3 URL,指向存储桶中的PDF文件
我想下载此文件,而不是在单击按钮时重定向/显示它。
我想过这样的事情
Router.route('download', {
path: '/d/:signedURL',
onAfterAction: function() {
var req = this.request;
var res = this.response;
res.setHeader('Content-disposition', 'attachment; filename=' + this.params.signedURL);
console.log(req, res);
}
}, {where: 'server'});
但不能让它起作用,有什么建议吗?
编辑:
Request URL:chrome-extension://invalid/
Request Headers
Provisional headers are shown
Referer:http://localhost:3000/d/https%3A/s3.amazonaws.com/tabler-development/08867c4b0guX7REeBvLHdLaMM%253D
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-DevTools-Request-Initiator:frontend
答案 0 :(得分:0)
尝试将您的服务器路由定义为HTTP GET restful路由,我认为您缺少res.end()
来确认响应是否已发送给客户端。
Router.route("/d/:signedURL",{
name:"download",
where:"server"
}).get(function(){
var req = this.request;
var res = this.response;
res.setHeader('Content-disposition', 'attachment; filename=' + this.params.signedURL);
res.end();
});