画像のアップロードを処理するコレクションfsパッケージをインストールしましたが、これまでに1つの画像を正常にアップロードしていません。コレクションfsを使用した簡単な画像のアップロード
私はこれは私がイメージ、ない画像をアップロードしようとするとこれは私のコレクションコード
SchoolImages = new FS.Collection("SchoolImages", {
stores: [new FS.Store.FileSystem("SchoolImages", {path: "~/meteor_uploads"})]
});
if (Meteor.isServer) {
SchoolImages.allow({
insert: function (userId, doc) {
return false;
},
update: function (userId, doc, fieldNames, modifier) {
return false;
},
remove: function (userId, doc) {
return false;
}
});
SchoolImages.deny({
insert: function (userId, doc) {
return true;
},
update: function (userId, doc, fieldNames, modifier) {
return true;
},
remove: function (userId, doc) {
return true;
}
});
}
である私のhtml
<input type="file" class="ip form-control" name="sn_edit" value="">
である私のイベントに
'change .ip': function(event, template) {
FS.Utility.eachFile(event, function(file) {
var yourFile = new FS.File(file);
SchoolImages.insert(yourFile, function (err, fileObj) {
if (err){
// handle error
alert('error');
} else {
// handle success depending what you need to d
alert('success');
}
});
});
}
をこのコードを持っていますアップロードされ、コレクションは作成されません。私のコードはエラーalert('error')
を与えます - 上のコードを見てください。
イメージを正常にアップロードするためにコードを修正するにはどうすればよいですか。
もしあなたが 'gridfs'へのアップロードに興味があるなら私の記事をお勧めします:http://mrmnmly.net/posts/saving-images-from-api-in-meteor-apps – mrmnmly
@lukaszkups私はチュートリアルを読んでいますしかし、あまりにも複雑なので、私はコンピュータからファイルを取得しています。しかし、ありがとう。 –