L
L
lemme2016-05-10 14:00:33
Node.js
lemme, 2016-05-10 14:00:33

How to properly handle multipart/form-data?

For example, there is a form with a text field and a file upload. What is the best option for downloading and saving the file?.
I use multer to upload, but the problem is that I can't access req.body without uploading the file. This is the problem, for example, I need to check the correctness of the received data, check this field for uniqueness, and only then upload the file. Now, you have to upload the file, then check everything, and if the check fails, then delete the file.
You can also upload files to the temp folder, and then, if the data is successfully saved to the database, transfer the file to the main one, but the essence does not change, you still have to save->check->delete/transfer
How do you upload the file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Tikhomirov, 2016-05-10
@Acuna

You know... it's obvious that each task needs its own solution. I use a server for moving, for storing files - Amazon S3, which itself checks the integrity of the downloaded file on the fly, and if it doesn't like something, it simply won't give a direct link to it as a result of the download. In terms of space and traffic, pennies come out, even if there are several TB of files. Because let's be honest, hosting (or your own server, it doesn't matter what) is not intended for file storage, it's just a server for running a virtual machine (unless you have hosting for 20 rubles a month, of course), for everything your tools. And the cost of space on the HDD in this case is simply unreasonably high.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question