Answer the question
In order to leave comments, you need to log in
Multer, how to disable large file uploads?
No matter how much he tries, no matter what he does, in any case, he first downloads the entire file (at least 50GB), and only then checks the size and extension (and deletes it, as in my example)
multer({
dest: './upload/',
limits: {
fileSize: 3*1024*1024
},
onFileUploadData: function(file, req, res) {
if (file.size > 1024*1024*3) {
return false; // Если файл не картинка, то file - вообще не выводиться, соответственно и размер не проверить
console.log('limit');
}
},
onFileUploadStart: function (file, req, res) {
console.log('Upload started');
var mime = file.mimetype;
if (mime != 'image/jpeg' && mime != 'image/png') {
res.end('Неправильный тип файла.');
return false;
}
},
onFileSizeLimit: function (file) {
console.log('Failed: ', file.originalname);
fs.unlink('./' + file.path);
},
onFileUploadComplete: function (file, req, res) {
res.end('file uploaded');
console.log('uploaded');
}
});
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