最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Best way to upload file using node js - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Dec 31, 2016 at 18:19 Joseph asked Dec 31, 2016 at 18:16 JosephJoseph 2,0162 gold badges13 silver badges20 bronze badges 2
  • nodejs only: ponentix./blog/9/file-uploads-using-nodejs-now-for-real – user956584 Commented Apr 29, 2017 at 19:06
  • check this out, it shows how to upload binary files using multer: youtube./watch?v=d8COHTGz2cc – Inzamam Malik Commented Oct 20, 2022 at 9:22
Add a ment  | 

2 Answers 2

Reset to default 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./2014/11/file-uploads-using-node-js/

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.

发布评论

评论列表(0)

  1. 暂无评论