我们如何在sails js中检查上传的文件扩展名? 我尝试了 skipper和 multer,但没有结果. 有什么建议吗? 在保存之前,您应该为每个文件使用saveAs选项. var md5 = require('md5');module.exports = { testUp
我尝试了 skipper和 multer,但没有结果.
有什么建议吗? 在保存之前,您应该为每个文件使用saveAs选项.
var md5 = require('md5'); module.exports = { testUpload:function(req,res){ // setting allowed file types var allowedTypes = ['image/jpeg', 'image/png']; // skipper default upload directory .tmphttp://img.558idc.com/uploadfile/ var allowedDir = "../../assets/images"; // don not define dirname , use default path req.file("uploadFiles").upload({ saveAs:function(file, cb) { var d = new Date(); var extension = file.filename.split('.').pop(); // generating unique filename with extension var uuid=md5(d.getMilliseconds())+"."+ extension; // seperate allowed and disallowed file types if(allowedTypes.indexOf(file.headers['content-type']) === -1) { // save as disallowed files default upload path cb(null,uuid); }else{ // save as allowed files cb(null,allowedDir+"/"+uuid); } } },function whenDone(err,files){ return res.json({ files:files, err:err }); }); } }