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.