Answer the question
In order to leave comments, you need to log in
Who worked with the multiparty module?
Hello, I have a problem, for example, I am uploading several files at once
$('#form').on('change', function (e) {
e.preventDefault()
var data = new FormData();
$.each(e.target.files, function (i, file) {
console.log(file)
data.append('photo' + i, file)
})
console.log(data)
$.ajax({
type: "POST",
url: "/upload",
data: data,
processData: false,
contentType: false,
cache: false,
success: function (data) {
console.log(data)
},
error: function (error) {
console.log(error)
}
})
})
part.byteCount
, content-length
and it stores the total length of the files, but how to find out the length of each file?
Answer the question
In order to leave comments, you need to log in
In the 'part' (part)
event handler , this information is not available. It is available either in the 'file' (name, file)
handler
form.on('file', function(name, file) {
console.log('File name: ' + name);
console.log('File size: ' + file.size);
});
/*
name - the field name for this file
file - an object with these properties:
fieldName - same as name - the field name for this file
originalFilename - the filename that the user reports for the file
path - the absolute path of the uploaded file on disk
headers - the HTTP headers that were sent along with this file
size - size of the file in bytes
*/
form.parse(req, function (err, fields, files) {
for (var name in files) {
console.log('got file named ' + name + ' with size = ' + files[name]['size']);
}
console.log('Upload completed!');
res.setHeader('text/plain');
res.end('Received ' + files.length + ' files');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question