node.js - Trouble uploading a file (Express/Node, Multer) -
hi using jade generate html , have form on page:
p upload new schedule #uploadnew form(id = "form1", action="/upload", method="post", enctype="multipart/form-data") input(type="file", id="control") br input(type="submit" value="upload" name="submit")
when select file , try upload, connection times out. doing wrong? using multer middleware upload well:
back in app.js:
var multer = require('multer'); var upload = multer({dest: './uploads'}); ... app.post('/upload', upload.single('submit'), function(req, res) { if (done == true) { console.log(req.files); res.end("file uploaded"); } });
add name field input box of "file" type:
p upload new schedule #uploadnew form(id = "form1", action="/upload", method="post", enctype="multipart/form-data") input(type="file" id="control" name="control") br input(type="submit" value="upload" name="submit")
you have not defined "done" anywhere ignoring it.
in upload.single(..) have pass name property of input field of "file" type (in case "control")
var multer = require('multer'); var upload = multer({dest: './uploads'}); ... app.post('/upload', upload.single('control'), function(req, res) { console.log(req.files); res.end("file uploaded"); });
Comments
Post a Comment