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可以做什么的更多详细信息。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下