How to process uploaded files in meteor.js

In php, you can use headers to force file downloads, as well as hide actual file locations, etc.

This is useful if you want certain users to be able to download certain files under certain conditions.

How do I do this in a meteor? I played with the Node.js fs module and got the binary version of the file on the client. But how would I turn this into an actual file that was uploaded?

Thanks!

+4
source share
1 answer

Three easy steps:

  • use meteorite
  • add iron-router package: mrt add iron-router
  • Create a server-side method to serve your file. Here is an example:

     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 an HTTP GET with one parameter name=name-of-pdf.pdf .

That is really all. Hope this is what you were looking for.

+7
source

Source: https://habr.com/ru/post/1485566/


All Articles