node. js uploads files using multiparty

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.