从Http NodeJS服务器下载文件[重复]

时间:2023-02-06 07:28:42

This question already has an answer here:

这个问题在这里已有答案:

I am developing a nodejs application in which I have a http server who responds to incoming POST commands. I do need to return an entire binary file. I can do it by using

我正在开发一个nodejs应用程序,其中我有一个响应传入POST命令的http服务器。我确实需要返回一个完整的二进制文件。我可以通过使用来做到这一点

response.end(file, 'binary); // where 'file' is the entire byte array

but I don't want to store the whole file in memory, I do want to send it by chunks. Is there any other way for doing this? I have googled without success.

但我不想将整个文件存储在内存中,我确实希望通过块发送它。这样做还有其他办法吗?我google搜索没有成功。

Thanks in advance,

提前致谢,

1 个解决方案

#1


1  

You can use response.write(...) to send chunks. See here: http://nodejs.org/api/http.html#http_response_write_chunk_encoding

您可以使用response.write(...)发送块。请参见:http://nodejs.org/api/http.html#http_response_write_chunk_encoding

Also, some additonal help in sending chunked responses can be found here: Node.js: chunked transfer encoding

此外,可以在此处找到一些有关发送分块响应的附加帮助:Node.js:chunked transfer encoding

#1


1  

You can use response.write(...) to send chunks. See here: http://nodejs.org/api/http.html#http_response_write_chunk_encoding

您可以使用response.write(...)发送块。请参见:http://nodejs.org/api/http.html#http_response_write_chunk_encoding

Also, some additonal help in sending chunked responses can be found here: Node.js: chunked transfer encoding

此外,可以在此处找到一些有关发送分块响应的附加帮助:Node.js:chunked transfer encoding