简体   繁体   中英

Streaming file without downloading it

If I have a large image for example (50MB+), and I want to load it into a Node.js page from an external URL, how can I render the page and stream the file to the client, without saving it to the server or having to wait for it to fully download before displaying the page?

All examples I've found so far rely on something like:

request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))

This requires the file to be saved before it can be outputted. How can I simply stream it rather than download it?

您从express获取的res对象是一个http.ServerResponse对象,这意味着您可以直接向其流式传输:

request('http://google.com/doodle.png').pipe(res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM