在php中,你可以使用header来强制下载文件,并隐藏实际文件位置等。这在你只想让特定的用户在特定条件下下载某些文件时非常有用。
在meteor中,我该怎么做呢?我已经试过Node.js fs模块,并成功在客户端检索了文件的二进制版本。但是如何将其转换为实际需要下载的文件呢?
谢谢!
在meteor中,我该怎么做呢?我已经试过Node.js fs模块,并成功在客户端检索了文件的二进制版本。但是如何将其转换为实际需要下载的文件呢?
谢谢!
mrt add iron-router
create a server method to serve your file. Here is how an exemple:
Router.map(function () {
this.route('get-image', {
where: 'server',
path: '/img',
action: function () {
console.log('retrieving ' + this.request.query.name);
this.response.writeHead(200, {'Content-type': 'image/png'}, this.request.query.name);
this.response.end(fs.readFileSync(uploadPath + this.request.query.name));
}
});
});
HTTP GET
,带有一个参数 name=name-of-pdf.pdf
。