In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people don't understand the knowledge points of this article "Node.js+express how to upload large files", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "Node.js+express how to upload large files".
The details are as follows:
For large file uploads we first introduce a library called multer:
npm install --save multer
Let's start by introducing libraries into our projects:
var multer = require ('multer ')var upload = multer({ dest:'uploads/'})//files will be uploaded to this directory
Specific ways to get:
app.post ('/upload', upload.single ('logo '), function(req, res){//send json data to the routing console.dir(req.file); res.send(req.p);})
Since uploading files requires a table, let's create a form called form first:
Document Single image upload
Then we introduce the form in the server:
var fs = require ('fs ')// /html interface from, used to demonstrate uploading files app.get ('/form', function(req, res){ var form = fs.readFileSync ('./ form.html',{ encoding : "utf8"}); res.send(form);})
Upload the file after running localhost:3000/form, you can see it in the upload directory of your project:
Although the upload was successful, w I n saw that the file name was confusing and the path was fixed:
Modify path and file name:
//Change the storage path for large files var createFolder = function(folder){ try{ fs.accessSync(folder); }catch( e ){ fs.mkdirSync(folder); }};var uploadFolder = './ upload/';//set the storage folder to the current directory/upload folder createFolder(uploadFolder);//disk storage var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, uploadFolder );//it will be placed under the/upload folder in the current directory (if there is no such folder, create a new one)}, filename: function (req, file, cb) {//set the filename here cb(null, file.originalname ); }})var upload = multer({ storage: storage })
Effect:
The above is the content of this article about "Node.js +express how to upload large files". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will be helpful to everyone. If you want to know more relevant knowledge content, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.