最佳答案
我正在使用 multer 上传我的图片和文档,但是这次我想限制上传,如果图片的大小 > 2mb。如何找到文档的文件大小?到目前为止,我尝试如下,但不工作。
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, common.upload.student);
},
filename: function (req, file, callback) {
console.log(file.size+'!!!!!!!!!!!!!!')======>'Undefined'
var ext = '';
var name = '';
if (file.originalname) {
var p = file.originalname.lastIndexOf('.');
ext = file.originalname.substring(p + 1);
var firstName = file.originalname.substring(0, p + 1);
name = Date.now() + '_' + firstName;
name += ext;
}
var filename = file.originalname;
uploadImage.push({ 'name': name });
callback(null, name);
}
});
Can anyone please help me?