multiparty using:Multiparty document Https://www.npmjs.com/package/multiparty
Here's a look at the process of using Formdata to submit a picture to the background:
Written in the previous words:
1. The front end of the example uses vue.js, but does not affect the upload idea.
2. Backstage through multiparty to parse Formdata
Step1: First look at the code of the front-end upload section:
This is I write a picture of the component, there is no image compression processing (we can use canvas for image compression, self-search).
This paragraph in fact also very good understanding, is the picture of the Formdata to the backstage to deal with.
Step2: Background Install multiparty plugin:
NPM Install Multiparty
Step3: Background processing Gets the uploaded picture:
We created a uploadimg.js to process the uploaded images, and we uploaded them via post localhost:3000/uploadimg.
The routing sub-module is described earlier:https://www.cnblogs.com/lewis-messi/p/9087258.html
1 /**2 * Administrator Module Uploadimg.js3 * @authors Lewis4 * @date May 23, 2018 10:13:295 * @description upload images6 */7 8 9 varExpress = require (' Express ');Ten varMultiparty = require (' multiparty ')); One varRouter =Express. Router (); A varUtil = require ('.. /utils '); - -Router.post ('/',function(req, res) { the varform =Newmultiparty. Form ();
//You can set the image upload path, default to the current user under the Temp folder -Form.uploaddir = Util.getrootdir () + "/static/img"; -Form.parse (req,function(Err, fields, files) { - //files is the information for uploading images + }); - }); + AModule.exports = router;
Here is some information about the files:
Of course, after you get this information, you can take the file to the next step (renaming):
node. js uploads files using multiparty