大家好,我使用的是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;
}
});
}
});
但它仍然不能工作,请帮助我如何修复这个问题。 如何在服务器端插入?