尝试将文件上传到我的数据库时,我收到一个阻止文件存储的匹配错误。
这是基本代码:
初始化:
UserImages = new FS.Collection("userImages", {
stores: [new FS.Store.FileSystem("userImages", {path: "~/uploads"})],
filter: {
maxSize: 1048576, //in bytes
allow: {
contentTypes: ['image/*'],
extensions: ['png', 'jpg']
},
onInvalid: function (message) {
if (Meteor.isClient) {
alert(message);
} else {
console.log(message);
}
}
}
});
if(Meteor.isServer){
UserImages.allow({
insert:function(userId, doc){
return true;
},
update:function(userId, doc, fields, modifier){
check(doc, Object);
return true;
},
remove:function(){
return true;
}
})
}
客户代码:
Template.editProfile.events({
'change #profileUpload':function(event, template){
var files = event.target.files;
for (var i = 0, ln = files.length; i < ln; i++) {
UserImages.insert(files[i], function (err, fileObj) {
if(err){
console.log(err);
}
});
}
}
});
勉强,如果我运行一个console.log(typeof文件),它会给我一个对象。但是当我用check(文件,对象)检查文件对象时,它给了我这个错误:
这是来自服务器的堆栈:
Exception in setTimeout callback: Error: Match error: Expected plain object
at checkSubtree (packages/check/match.js:279:1)
at check (packages/check/match.js:32:1)
at UserImages.allow.update (app/server/allowances.js:91:7)
at packages/mongo/collection.js:1041:1
at Array.every (native)
at Function._.every._.all (packages/underscore/underscore.js:219:1)
at [object Object].Mongo.Collection._validatedUpdate (packages/mongo/collection.js:1038:1)
at [object Object].m.(anonymous function) (packages/mongo/collection.js:851:1)
at Object.methods.rateLimit.callFunctionsInQueue (packages/matteodem:easy-security/lib/easy-security.js:72:1)
at packages/matteodem:easy-security/lib/easy-security.js:116:1
是否有人遇到此问题或有解决方法?我也尝试过Match.Any的各种变通方法,但是我得到一个错误告诉我所有的参数都没有针对check()运行;
我在这里检查了问题: https://github.com/CollectionFS/Meteor-cfs-base-package/issues https://github.com/CollectionFS/Meteor-CollectionFS/issues
但到目前为止找不到解决方案。
感谢您的帮助!