node.js - Uploading file with express -


i trying make simple file server able save file using express:

var app = express(); app.use(express.bodyparser({uploaddir:'./uploads'})) app.post('/upload', function(req, res, next) {     console.log("uploading file");      req.on('data', function(raw) {         console.log('received data: ' + raw);     });      req.on('end', function() {         console.log('file uploaded');         res.send(200);     });  }); 

i getting empty file in "uploads" folder.

what missing?

maybe silly question new node.js.

edit: more information...

i sending client:

post /upload http/1.1 connection: close content-length: 42 content-type: multipart/form-data; boundary="mime_boundary_572b1a2b457d3267" cookie: session.id=b268b12e-0c05-11e3-8702-7a7919510927 host: localhost:8080 transfer-encoding: chunked   client 3 received message: e4 --mime_boundary_572b1a2b457d3267 content-disposition: form-data; name="test1.txt"; filename="test1.txt" content-type: application/octet-stream  file1 client in w7 send server. --mime_boundary_572b1a2b457d3267--  0 

in 2 chuncks.

regarding > getting empty file in "uploads" folder,

you must save (decoded) request body file.

also note client content encoding multipart. resembling multipart content tricky. can use bodyparser middleware that.

take @ this answer more info.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -