Simple implementation of node. js image Upload

Source: Internet
Author: User
The example of this article for everyone to share the node. js image upload specific code for your reference, specific content as follows

1.node-formidable

Components to help with file uploads

2.app.js

var formidable = require (' formidable '); var http = require (' http '); var sys = require (' sys ');  Http.createserver (function (request, response) {if (Request.url = = '/upload ' && request.method.toLowerCase () = =    ' Post ') {Console.log (' upload Requet ') uploadrequest (request,response);  Return  } enterrequest (Request,response)}). Listen (3000);  function enterrequest (request, Response) {Response.writehead ($, {' Content-type ': ' text/html '}); Response.End (' <form action = "/upload" enctype= "Multipart/form-data" method= "post" > ' + ' <input type = "Te    XT "name =" title "/> <br> ' + ' <input type =" File "name=" upload "multiple=" multiple "/> <br/> ' +  ' <input type= ' "Submit" value= "Upload Now"/> ' + ' </form> ');} /** * Processing the uploaded logic * @param request * @param response */function uploadrequest (request,response) {var form = new Formidable.  Incomingform (); Form.parse (Request, function (Err, fields, files) {Response.wriTehead ($, {' Content-type ': ' Text/plain '});    Response.Write (' reviced upload file ');  Response.End (Sys.inspect ({fields:fields, files:files})); });}

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.


Related Article

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.