正如标题,现在我无法在上传前检查文件类型。我只验证文件上传成功后不允许保存数据。下面是基本代码
updateAvatar : function(data, context, req, res) {
req.file('avatar').upload({
dirname: '../../assets/images/avatar'
}, function (err, files) {
var allowExts = ['image/png', 'image/gif', 'image/jpeg'];
if (err)
return res.serverError(err);
if (files.length === 0)
return res.badRequest('No file was uploaded!');
if (allowExts.indexOf(files[0].type) == -1)
return res.badRequest('File type is not supported!');
// save database here
});
}
我应该怎么做才能获得正确的代码?对不起,我的英语不好!非常感谢!