A
A
akdes2018-10-24 17:49:49
JavaScript
akdes, 2018-10-24 17:49:49

How to make a file upload without saving it in node.js?

Hi all.
I'm making a file uploader on the backend.
There is a need to upload any media files such as pictures and videos, or maybe an archive ... Size max 1 GB per file. The files will be uploaded to S3. It is necessary to solve this on the backend, because of the s3 credits, and when loading, there will be a record in the database.
Because I'm worried about the memory (amount) of the service, both working and file, I would like to take only pieces when loading, which are then loaded further on S3 and then deleted from memory. at the same time, the service thread should not be blocked by all sorts of fs.readFile
For S3, there is an implementation
Thank you in advance
indicated in the examples how to work with a file that has a physical path - due to lack of experience, I don’t understand / can’t find how I can start this with loading a file with a regular post-request.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
akdes, 2018-10-26
@akdes

Key points that exclude uploading to S3 directly from the frontend:
The service will be basic and will be used in several projects. When moving from S3 or changing the logic, you will have to change all projects individually.
Solution for the moment:
On the frontend, the file will be cut into pieces of 5 MB and uploaded asynchronously via multipartUpload to the backend.
Those. at the beginning of the download, the download identifier will be transmitted and at the last. pieces it will remain.
At the end, there will be a call to the backend, which will collect the pieces into one using S3.
Thus, you can horizontally increase resources, without fear of problems with loading.

I
Ivan Shumov, 2018-10-24
@inoise

On S3, you can download directly, bypassing your server in principle. You generate a one-time policy and the download goes through it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question