我正在尝试使用nodejs中的multer上传250000行的excel文件。我能够成功上传50000行的文件,但上传文件时有250000行,大小为7.3 MB。我的代码在下面 -
var storage = multer.diskStorage({ //multers disk storage settings
destination: function (req, file, cb) {
cb(null, env.uploadPath)
},
filename: function (req, file, cb) {
var servFileName = Date.now()+'_'+file.originalname;//Work same as +new Date();
//cb(null, file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1])
cb(null, servFileName)
}
});
var upload = multer({ //multer settings
storage: storage,
limits: { fileSize: 10000000 },
fileFilter : function(req, file, callback) { //file filter
// if (['xls','xlsx'].indexOf(file.originalname.split('.')[file.originalname.split('.').length-1]) === -1) {
// return callback(new Error('Wrong extension type'));
// }
//matching extension after filename
console.log("multer console 1");
var regex = new RegExp(/.(?=xlsx|xls|xlsx.zip|xls.zip)/);
if(regex.exec(file.originalname)){
callback(null, true);
}else{
return callback(new Error('Wrong extension type'));
}
}
}).single('file');
module.exports = upload;
我无法找出问题所在。请帮忙。 在此先感谢!!!
答案 0 :(得分:0)
您可以尝试使用以下方法将某些值设置为最大尺寸:
var upload = multer({
limits: { fileSize: YOUR_MAX_SIZE},
....
})