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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -