Answer the question
In order to leave comments, you need to log in
Why can't I read the file loaded from the form?
Good afternoon.
Why can't read the file uploaded from the form?
Always throws an error : Cannot read property 'buffer' of undefined
form (PUG):
form(action='/', method='POST' , enctype="form-data")
p
input(type='file', name='down', value='')
input(type='submit',name="downloaded_file", value='загрузить')
...
var multer = require('multer')
var upload = multer({ dest: 'uploads/' })
...
app.post('/', upload.single('down'), function (req, res, next) {
var raw = new Buffer(req.file.buffer.toString(), 'utf-8');
fs.writeFile('./uploads/test1.txt', raw, function (err) {
if (err) {
console.log('Error');
return next(err);
}
res.end('Success!');
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question