4

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?

2

2 Answers 2

2

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/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I wil use that in my projects.
Sure, it was my pleasure
In case this helps future readers: this StackOverflow answer provides fairly concise code for accomplishing this without dragging in Multer or its 28 dependencies.
0

If someone uses EXPRESS with NodeJS then express-fileupload is the simple and most powerful node-package to upload file(s) on the server. There you'll find all the options and steps to use this package.

1 Comment

Tho it's very heavy, unpacked size 1.21MB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.