node.js - Multer file upload error Error: Unexpected field -
i trying upload file on nodejs using multer gives error of error: unexpected field
.
i following tutorial http://code.runnable.com/vnx-t8fdt5y4x-mv/fileupload-for-node-js-and-hello-world.
here code:
var express=require("express"); var multer = require('multer'); var app=express(); var done=false; /*configure multer.*/ //app.use(); /*handling routes.*/ app.get('/',function(req,res){ res.sendfile("./index.html"); }); app.post('/',multer({ dest: './uploads/'}).single('upl'),function(req,res){ if(done==true){ console.log(req.files); res.status(204).end(); } }); /*run server.*/ app.listen(3000,function(){ console.log("working on port 3000"); });
on html
error facing
error: unexpected field @ makeerror (c:\users\abhishek\desktop\ospl_energy\node js\node_modules\multer\lib\make-error.js:12:13) @ wrappedfilefilter (c:\users\abhishek\desktop\ospl_energy\node js\node_modules\multer\index.js:39:19) @ busboy.<anonymous> (c:\users\abhishek\desktop\ospl_energy\node js\node_modules\multer\lib\make-middleware.js:112:7) @ emitmany (events.js:127:13) @ busboy.emit (events.js:201:7) @ busboy.emit (c:\users\abhishek\desktop\ospl_energy\node js\node_modules\busboy\lib\main.js:31:35) @ partstream.<anonymous> (c:\users\abhishek\desktop\ospl_energy\node js\node_modules\busboy\lib\types\multipart.js:213:13) @ emitone (events.js:96:13) @ partstream.emit (events.js:188:7) @ headerparser.<anonymous> (c:\users\abhishek\desktop\ospl_energy\node js\node_modules\dicer\lib\dicer.js:51:16)
html filename , myimage should same .single('upl')
so code is
var express=require("express"); var multer = require('multer'); var app=express(); var done=false; /*configure multer.*/ //app.use(); /*handling routes.*/ app.get('/',function(req,res){ res.sendfile("./index.html"); }); app.post('/',multer({ dest: './uploads/'}).single('myimage'),function(req,res){ if(done==true){ console.log(req.files); res.status(204).end(); } }); /*run server.*/ app.listen(3000,function(){ console.log("working on port 3000"); });
Comments
Post a Comment