Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to upload file using node js

what is the best way of handling file uploads using node js? I want my user to upload a profile image, the uploader should have this functionality: -validated that the image should be at min 200 * 200 -file must be only png, jpg, jpeg or gif -and other stuff that an uploader should have (for example renaming the file before saving that and lots of other, you know) So, what package do you suggest me to use? is it better to use package or native node js?

like image 411
Joseph Avatar asked Oct 25 '25 20:10

Joseph


1 Answers

For handling file uploads, you need to handle the multipart/form-data which contain the file and its metadata.

You can roll your own solution by handling this part, but I suggest you to go for Multer until you really understand all the specifics as it can get quite tedious.

Multer has abstracted everything for you and gives you a very simple middleware interface to act on the form-data quite easily.

You can also look at this blog post which explains file uploading in node via multer with example: https://codeforgeek.com/2014/11/file-uploads-using-node-js/

like image 177
Lokesh Devnani Avatar answered Oct 27 '25 09:10

Lokesh Devnani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!