there are all kinds of posts about this, but I'm still not getting it. I want to upload a *.csv and read and process its contents.
my jade file is this
//views/import.jade
extends layout
block content
h1= title
form(action="/import", method="post", enctype="multipart/form-data")
input(type="file", name="ufile")
input(type="submit", name="Upload")
--
I changed the code, but req.files is undefined
//routes/index.js
/* import page. */
router.get('/blah', function(req, res, next) {
res.render('import', { title: 'Import Data' });
});
router.post('/import', function(req, res) {
console.log(req.files);
});
module.exports = router;
The below tutorial gets me super close to where I need to be.
NOTE: In the form, it should be:
action="/uploads/upload"
I can finally upload and read *.csv files.
http://www.e-zest.net/blog/how-to-handle-file-upload-with-node-and-express-4-0
Here is one of the secret ingredients for reading form data:
https://github.com/expressjs/multer
I hope this may be of use to someone else who was stuck like me (for 3 days!).