admin管理员组文章数量:1429481
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
2 Answers
Reset to default 2For 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.
本文标签: javascriptBest way to upload file using node jsStack Overflow
版权声明:本文标题:javascript - Best way to upload file using node js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745496607a2660833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论