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可以做什么的更多详细信息。
热门推荐
6 合字的祝福语简短
10 姐姐女儿结婚祝福语简短
11 圆圆的祝福语简短
12 离别简短的祝福语大全
13 美好的成语祝福语简短
14 男朋友祝福语简短新年
15 虎年开新车祝福语简短
16 小姨生日祝福语简短独特
17 国庆简短幽默祝福语
18 长辈生日祝福语简短女性