Tha*_*Dao 9 javascript node.js sails.js bluebird skipper
作为标题,现在我无法在上传之前检查文件类型.我只验证并且在文件上传成功后不允许保存数据.以下是基本代码
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
});
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做正确的代码?对不起,我的英语不好!非常感谢!
归档时间: |
|
查看次数: |
1024 次 |
最近记录: |