将 CollectionFS 与流星一起使用时要“发布”什么
What to `publish` when using CollectionFS with meteor
我正在尝试使用 CollectionFS 获得最简单的示例。所以我开始了一个新项目
meteor create test
cd test
meteor add cfs:standard-packages
meteor add cfs:filesystem
现在我添加 README.md 中的所有代码。
在common.js
(创建)
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
所以在 server.js
(创建)
Images.allow({
'insert': function () {
// add custom authentication code here
return true;
},
});
在 test.js
中(由 meteor 创建的编辑)
Template.hello.helpers({
counter: function () {
return Session.get('counter');
},
// -- added ---
images: function() {
return Images.find();
},
});
// added
Template.hello.events({
'change .myFileInput': function(event, template) {
var files = event.target.files;
for (var i = 0, ln = files.length; i < ln; i++) {
Images.insert(files[i], function (err, fileObj) {
// Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
});
}
}
});
在 test.html
中(由 meteor 创建的编辑)
<!-- added -->
<input type="file" class="myFileInput"/>
<hr/>
{{#each images}}
<div>
{{this.name}}: <a href="{{this.url}}" target="_blank"><img width="50" src="{{this.url}}" alt="" class="thumbnail" /></a>
</div>
{{/each}}
所以一切正常。我设置了一张图片,它被上传,它神奇地出现了
然后我删除autopublish
meteor remove autopublish
我需要发布和订阅什么才能让它再次运行?
我尝试过的事情
在server.js
if (Meteor.isServer) {
Meteor.publish("images");
}
在test.js
if (Meteor.isClient) {
Meteor.subscribe("images");
}
运气不好
if (Meteor.isServer) {
Meteor.publish("images", function() {
return Images.find();
});
}
您获取的客户端密码正确
我正在尝试使用 CollectionFS 获得最简单的示例。所以我开始了一个新项目
meteor create test
cd test
meteor add cfs:standard-packages
meteor add cfs:filesystem
现在我添加 README.md 中的所有代码。
在common.js
(创建)
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
所以在 server.js
(创建)
Images.allow({
'insert': function () {
// add custom authentication code here
return true;
},
});
在 test.js
中(由 meteor 创建的编辑)
Template.hello.helpers({
counter: function () {
return Session.get('counter');
},
// -- added ---
images: function() {
return Images.find();
},
});
// added
Template.hello.events({
'change .myFileInput': function(event, template) {
var files = event.target.files;
for (var i = 0, ln = files.length; i < ln; i++) {
Images.insert(files[i], function (err, fileObj) {
// Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
});
}
}
});
在 test.html
中(由 meteor 创建的编辑)
<!-- added -->
<input type="file" class="myFileInput"/>
<hr/>
{{#each images}}
<div>
{{this.name}}: <a href="{{this.url}}" target="_blank"><img width="50" src="{{this.url}}" alt="" class="thumbnail" /></a>
</div>
{{/each}}
所以一切正常。我设置了一张图片,它被上传,它神奇地出现了
然后我删除autopublish
meteor remove autopublish
我需要发布和订阅什么才能让它再次运行?
我尝试过的事情
在server.js
if (Meteor.isServer) {
Meteor.publish("images");
}
在test.js
if (Meteor.isClient) {
Meteor.subscribe("images");
}
运气不好
if (Meteor.isServer) {
Meteor.publish("images", function() {
return Images.find();
});
}
您获取的客户端密码正确