javascript - Cannot read "path" property of undefined Nodejs -
here jade file
form(method="post", action="/upload", enctype="multipart/form-data") input(type="file", name="logname") button(type="submit") upload
and index.js file
/* home page. */ router.get('/', function (req, res) { res.render('fileupload', { title: 'building log file viewer' }); }); var formidable = require('formidable'), fs = require('fs'), util = require('util'); /* post file upload */ router.post('/upload', function (req, res) { var form = new formidable.incomingform(); form.parse(req, function (err, fields, files) { fs.readfilesync(files.upload.path, function (err, data) { if (err) throw err; console.log("test"); }) }); });
i keep getting typeerror property property "path" undefined; however, when sumbit code under http.createserver, instead of router.post, works fine. have tried asychronous file reading, , gave me same error. ideas?
please try
fs.readfilesync(files.logname.path, function (err, data){ ... });
instead of
fs.readfilesync(files.upload.path, function (err, data) { ... });
Comments
Post a Comment