Answer the question
In order to leave comments, you need to log in
Why is file upload not working in nodejs via multer?
I'm trying to upload pictures.
My router:
upload.post('/', function(req, res) {
console.log(req.body)
console.log(req.files)
});
<form id="photo-form" name="upload" enctype="multipart/form-data" method="post" action="/upload">
<label>
<input id="files-field" type="file" multiple="multiple" />
</label>
<hr>
<input type="submit">
</form>
var app = express();
var multer = require('multer')
app.use(multer({ dest: './uploads'}))
req.body
, req.file
I have {}
, that is, nothing comes. What could be the problem? var items = $('#files-field')
$.ajax({
type: "POST",
url: '/upload',
data: items,
processData: false,
dataType: 'multipart/form-data',
success: function(){
window.location.href = '/';
}
});
{'[object Object]':' '}
and there are no files. What's wrong here?
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