【问题标题】:Meteor Collection FS insert not working after removing insecure packages删除不安全的包后 Meteor Collection FS 插入不起作用
【发布时间】:2015-11-05 06:20:21
【问题描述】:

从标题中可以看出,在删除不安全的包后,我的 Collection FS 出现问题。

我正在使用 cfs:gridfs。

删除包:不安全、自动发布

我的 HTML

<template name="image_upload">
    <input class="fileinput btn" type="file" name="file" accept="image/*" {{disableButton}}>
</template>

在我的服务器 Publications.js 中

Meteor.publish("image_upload", function () {
    return Images.find();
});

我的库/collections.js

Images = new FS.Collection("images", {
    stores: [
    new FS.Store.GridFS("images"),
    ],
    filter: {
        allow: {
            contentTypes: ['image/*']
        }
    }
});
Images.deny({
    insert : function() {return false},
    update : function() {return false},
    remove : function() {return false},
    // insert : function() {return false},
});
Images.allow({
    insert: function() { return true },
    update: function() { return true },
    remove: function() { return true }
});

还有我的图片上传活动

Template.image_upload.events({
    'change .fileinput': function(event, template){
        // console.log('abs');
        var username = Meteor.user().username;
        FS.Utility.eachFile(event, function(file){
            var fsFile = new FS.File(file);
            fsFile.username = username;
            fsFile.tweetkey = Session.get('tweetkey');
            Images.insert(fsFile, function(err) {});
        });
    }
});

我的包裹

# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

meteor-platform
accounts-ui
accounts-password
msavin:mongol
cfs:standard-packages
cfs:gridfs
iron:router
mizzao:jquery-ui
mizzao:bootstrap-3
fortawesome:fontawesome
reywood:publish-composite
momentjs:moment

如果有人可以帮助我,那就太好了!

【问题讨论】:

  • 您收到了哪些错误消息?
  • @Curtis 没有错误消息...顺便说一句,我删除了插件自动发布

标签: templates meteor collections insert fs


【解决方案1】:

也尝试为Images.deny({}) 设置规则。他们将覆盖您的 allow ,但据我所知,应首先添加 deny 规则。在他们提到的文档中:

只有在没有拒绝规则返回 true 并且至少一个允许规则返回 true 时,Meteor 才允许写入。

编辑:在看到您的控制台没有任何错误后,我认为这只是订阅问题(删除autopublish 将迫使您订阅每条路线)。尝试更改您的模板和路由器,例如:

客户端\image_upload.html

<template name="image_upload">
  <input class="fileinput btn" type="file" name="file" accept="image/*" {{disableButton}}>

  {{#each images}}
    <div class="img">
      {{this.original.name}}
    </div>
  {{/each}}
</template>

lib\router.js

Router.route('/', {
  name: 'image_upload',
  action: function () {
    this.render('image_upload');
  },
  data: function () {
    return {
      images: Images.find({})
    };
  },
  waitOn: function () {
    return [
      Meteor.subscribe('image_upload')
    ];
  }
});

将来,请尝试查看https://github.com/meteorhacks/subs-manager 以获得更好的订阅管理器、缓存等。

【讨论】:

  • 我在我的问题中添加了上面的拒绝规则,但它仍然不起作用。当我添加自动发布包时,上传效果很好,但我不想使用它
  • 您能提供在.meteor/packages 中找到的列表吗?另外,您的服务器终端上是否显示任何错误?浏览器控制台上的任何内容?
  • 我添加了上面的包。服务器的终端或浏览器的控制台中没有显示错误...
  • 我已经用正确的方式编辑了我的答案以订阅iron:router
  • 谢谢!现在很好用!但是我怎样才能显示图像?
【解决方案2】:

你有这个:

Meteor.publish("image_upload", function () {
    return Images.find();
});

但“image_upload”是您的模板名称,而不是您的集合名称。您的收藏称为“图片”。

在服务器上,您可以定义将哪些数据(集合)发布到客户端。试试这个:

Meteor.publish("images", function () {
    return Images.find();
});

【讨论】:

  • 我也添加了这个,但它仍然不起作用......我将分开我的问题,您可以更轻松地理解代码
  • 现在我在浏览器控制台中收到错误:提供的值“未定义”不是 XMLHttpRequestResponseType 类型的有效枚举值。
猜你喜欢
  • 1970-01-01
  • 2015-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多