【发布时间】:2014-05-27 11:28:49
【问题描述】:
大家好,我正在使用 collectionfs + gridfs + cfs 文件系统, 在 collectionfs 文档中,我找到了如何在客户端插入文件,如下所示:
Template.myForm.events({
'change .myFileInput': function(event, template) {
FS.Utility.eachFile(event, function(file) {
Images.insert(file, function (err, fileObj) {
//Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
});
});
}
});
在这种情况下将在客户端插入文件,但在我的情况下,我删除了不安全的,所以不能在客户端进行插入,我尝试在服务器端进行插入。所以这是我的代码:
Template.myForm.events({
'change . myFileInput': function (event, template) {
FS.Utility.eachFile(event, function (file) {
var reader = new FileReader();
reader.onload = function (fileLoadEvent) {
Meteor.call('ImageUpload', file, reader.result, function (err, res) {
if (err) {
console.log(err);
} else {
alert(res);
}
});
};
reader.readAsBinaryString(file);
});
}
});
server.js:
Meteor.methods({
ImageUpload: function (fileInfo, fileData) {
console.log(fileInfo);
Images.insert(fileInfo, fileData, function (err, fileObj) {
if (err) console.log(err)
else {
//Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
console.log(fileObj);
return fileObj._id;
}
});
}
});
但它仍然不起作用,请帮助我如何解决这个问题。 如何在服务器端插入?
【问题讨论】:
-
它在客户端不起作用,因为您必须定义允许/拒绝规则。我建议您在客户端执行此操作;) 检查流星文档。
-
:o 但是我删除了不安全的,所以不能从客户端插入,它总是错误
-
您是否定义了允许/拒绝规则?
-
哎呀抱歉我不知道,我必须在哪里定义它?可以举个例子吗?
标签: javascript meteor gridfs meteorite