Answer the question
In order to leave comments, you need to log in
How to download a large file from a distant server?
Hello.
I write for a web service on nodejs.
The task is to download a file from a remote server and send it immediately to the client, without saving it to the server disk.
The client sends the file id in the database to the server, I find the url where the file is located and start downloading.
The general principle of downloading, I think, will be the following: we start downloading and periodically send what has been downloaded to the client until the file runs out.
How can this be done?
Answer the question
In order to leave comments, you need to log in
https://nodejs.org/api/stream.html
You need to open a stream for downloading from a remote server and write it to the request stream
The `request` module allows you to receive data from the server in the form of a stream.
With the use of streams, the general principle is exactly as described. But it is already implemented, you just need to use it correctly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question