L
L
lutaev232015-12-04 12:40:13
JavaScript
lutaev23, 2015-12-04 12:40:13

How do I stream from Amazon S3 to a client?

Please tell me the solution to the problem: there is a server on node and there is storage on Amazon S3. How to organize (or where you can read about it) the following scheme:
1. A request is made to the URL, for example /watch/video1.mp4
2. The node catches the request and sends the request to Amazon.
3. In response, a file (or stream?) is returned, which the node sends to the client.
4. It is not visible from the client side that we use Amazon.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill, 2015-12-04
@lutaev23

It looks like your logic is correct except for one thing, judging by the documentation , Amazon does not know how to give streams, but supports the Range header in the request. You can download content from the Amazon server in chunks as needed, and give those chunks to the user via stream . You just have to correctly calculate the size of the chunk and the moment when you need to start downloading the next chunk (otherwise there will not be enough memory). Luckily writable.write(), it returns false if the data you passed will be buffered for sending instead of being sent right away.
If you have more specific questions, please create them separately.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question