meteor 集合FS
例子
但是,如果您真的很重视存储,并且想要存储数百万个图像,那么您将需要利用Mongo的GridFS基础架构,并为自己创建一个存储层。为此,您将需要出色的CollectionFS子系统。
首先添加必要的包。
meteor add cfs:standard-packages meteor add cfs:filesystem
并将文件上传元素添加到您的对象模型。
然后在客户端添加一个事件控制器。
Template.yourTemplate.events({
'change .your-upload-class': function(event, template) {
FS.Utility.eachFile(event, function(file) {
var yourFile = new FS.File(file);
yourFile.creatorId= Meteor.userId(); //添加自定义数据
YourFileCollection.insert(yourFile, function (err, fileObj) {
if (!err) {
//做回调的东西
}
});
});
}
});并在您的服务器上定义您的集合:
YourFileCollection = new FS.Collection("yourFileCollection", {
stores: [new FS.Store.FileSystem("yourFileCollection", {path: "~/meteor_uploads"})]
});
YourFileCollection.allow({
insert: function (userId, doc) {
return !!userId;
},
update: function (userId, doc) {
returndoc.creatorId== userId
},
download: function (userId, doc) {
returndoc.creatorId== userId
}
});感谢Raz提供了这个很好的例子。您需要查看完整的CollectionFS文档,以了解有关所有CollectionFS可以做什么的更多详细信息。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短