In php you can use headers to force downloads of files, and also to hide actual file locations etc.
This is useful if you only want certain users under certain conditions to be able to download certain files.
How would I do this in meteor? I've played around with the Node.js fs module, and managed to retrieve a binary version of the file on the client. But how would I turn this to an actual file that's downloaded?
Thanks!
Three easy steps:
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));
}
});
});
In this example the request is a HTTP GET
with one parameter name=name-of-pdf.pdf
.
That's really all. Hope it was what you were looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With