How to send files with node.js


Question

How do you send files on node.js/express.

I am using Rackspace Cloudfiles and wanna send images/videos to their remote storage but I am not sure that it's as simple as reading the file (fs.readFileSync()) and send the data in the request body, or is it?

What should the headers be.

What if it's a very large file on a couple of GBs?

Is it possible to use superagent (http://visionmedia.github.com/superagent) for this or is there a better library for sending files?

Please give me some information about this.

Thanks!

1
27
2/17/2012 12:01:47 AM

app.get('/img/bg.png', function(req, res) {
  res.sendFile('public/img/background.png')
})

https://expressjs.com/en/api.html#res.sendFile

use "res.sendFile". "res.sendfile" is deprecated.

50
5/30/2018 6:36:22 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon