当我试图将一张照片插入数据库时,我得到了上面的错误。奇怪的是,文档的文件端插入得很好,但没有插入到块端。我环顾了一下网络,但没有得到任何关于问题可能是什么的提示。有没有人看过这个错误并能帮上忙?
这是我的代码。
collections.js
PhotosFS = new CollectionFS('photos');
PhotosFS.allow({
insert: function (userId, file) {
return userId && file.owner === userId;
}
});events.js
Template.createPhotos.events({
"change input[type='file']": function (e, tmpl) {
var file = e.target.files;
Session.set('currentFile', file[0]);
},
"click .save-button": function (e, tmpl) {
var file = Session.get('currentFile');
PhotosFS.storeFile(file, {
name: name,
photographer: photographer,
caption: caption,
});
}
});发布于 2014-02-12 21:40:21
我猜这与在上传到数据库之前将文件存储在会话中有关,因为如果您在对输入文件进行更改后直接上传文件,那么它上传得很好。当它直接从输入文件更改事件上载时,它将作为文件上载。但是当它存储在会话中然后上传时,它会作为一个对象上传。我猜CollectionFS块不能识别对象。我不知道。但我确实知道,对于我的特定应用程序,在输入文件更改事件之后直接上传文件是没有意义的。
但我想我不得不这么做
Template.createPhotos.events({
"change input[type='file']": function (e, template) {
var file = e.target.files;
var fileId = PhotosFS.storeFile(file[0]);
Session.set('currentFile', fileId)
},
"click .save-button": function (e, tmpl) {
var file = Session.get('currentFile');
PhotosFS.storeFile(file, {$set: {
name: name,
photographer: photographer,
caption: caption,
}});
}
});我不会接受我自己的答案,因为我仍然希望有人能找到一种方法,在上传之前将文件存储在会话中。
https://stackoverflow.com/questions/21720021
复制相似问题