Meteor CollectionFS错误-未捕获错误:CollectionFS:file.slice不受支持?
我在尝试将照片插入数据库时遇到上述错误。奇怪的是,文档的文件端插入得很好,但块端没有插入任何内容。我环顾了一下网络,但没有得到任何关于问题可能是什么的提示。有人看到这个错误并能提供帮助吗 这是我的密码 collections.jsMeteor CollectionFS错误-未捕获错误:CollectionFS:file.slice不受支持?,meteor,Meteor,我在尝试将照片插入数据库时遇到上述错误。奇怪的是,文档的文件端插入得很好,但块端没有插入任何内容。我环顾了一下网络,但没有得到任何关于问题可能是什么的提示。有人看到这个错误并能提供帮助吗 这是我的密码 collections.js PhotosFS = new CollectionFS('photos'); PhotosFS.allow({ insert: function (userId, file) { return userId && file.o
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,
});
}
});
我猜这与在上传到数据库之前将文件存储在会话中有关,因为如果您在更改输入文件后直接上传文件,它会很好地上传。直接从输入文件更改事件上载时,它将作为文件上载。但当它存储在会话中,然后上载时,它将作为对象上载。我猜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,
}});
}
});
我不会接受我自己的答案,因为我仍然希望有人能找到一种方法,在上传之前将文件存储在会话中