我正在尝试通过 Meteors CollectionFS 上传图像,但客户端代码中没有任何错误,所以我不确定是什么损坏了。我看到 console.log 消息“内部上传”,但我没有看到来自 Images.insert 回调的任何成功或失败消息。帮助。
myproject/client/upload.html
<template name="upload">
<form>
<input class="upload" type="file" id="upload" name=".../">
</form>
</template>
myproject/client/upload.js
Template.providerblock.events({
'click .upload': function(event, template) {
event.preventDefault();
var photo = $('#upload')[0];
var file = photo.files[0];
console.log("inside upload");
Images.insert(file, function (err, fileObj) {
if(err) {
console.log("unable to upload file");
} else {
console.log("file upload success");
}
});
},
});
myproject/lib/images.js
var Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
Images.allow({
insert: function() {
return true;
},
update: function() {
return true;
},
remove: function() {
return true;
},
download: function() {
return true;
}
});