javascript - CollectionFS 访问被拒绝 403 错误 #Meteor JS

标签 javascript mongodb meteor

我正在使用 collectionFS 进行文件上传,我的代码如下。登录用户可以将图像插入图像集合,我也可以看到该文件已上传到服务器上。在删除能够查看图像和下载的不安全包之前显示图像链接和下载按钮。从项目中删除不安全的包后。图片不显示也无法下载(可以检索图片名称和 url),接收访问被拒绝 403 错误。我真正想要的是签名用户可以将文件插入服务器并且每个人都可以看到图像,也可以下载文件。我写了允许规则以及发布和订阅。这里有什么问题?
js文件

    if (Meteor.isClient) {
    Template.myForm.events({
      'change .myFileInput': function(event, template) {
        FS.Utility.eachFile(event, function(file) {
          var fsFile = new FS.File(event.target.files[0]);
          fsFile.owner = Meteor.userId();
          Images.insert(file, function (err, fileObj) {
            //If !err, we have inserted new doc with ID fileObj._id, and
            //kicked off the data upload using HTTP
          });
        });
      }
    });


    Template.imageView.helpers({
      images: function () {
        return Images.find(); // Where Images is an FS.Collection instance
      }
    });
    Meteor.subscribe('images');
  }





    if (Meteor.isServer) {
        Meteor.startup(function () {
          // code to run on server at startup
        });
        Meteor.publish('images', function(){
          return Images.find();
        });
      }


      Images = new FS.Collection("images", {
    stores: [new FS.Store.FileSystem("images", {path: "~/uploaded"})],
  });

  Images.allow({
    insert: function(userId, doc){
      return !!userId;
    },
    update: function(userId, doc){
      return !!userId;
    },
    remove: function(userId, doc){
      return false;
    }
  });

html文件

    <head>
  <title>uploader</title>
</head>

<body>
  {{> loginButtons}}
  {{> imageView}}
  {{>myForm}}
</body>

<template name="imageView">
    <div class="imageView">
        {{#each images}}
        <div>
            <a href="{{this.url}}" target="_blank"><img src="{{this.url}}" alt="" class="thumbnail" />{{this.url}}</a><br/>
            <strong>{{this.name}}</strong> <a href="{{this.url download=true}}" class="btn btn-primary">Download</a>
        </div>
        {{/each}}
    </div>
</template>

<template name="myForm">
    <p>
        Please specify a file, or a set of files:<br>
        <input type="file" name="datafile" class="myFileInput">
    </p>
</template>

最佳答案

如果您关闭了不安全和自动发布,并且您通过订阅访问您的文件,我相信您只需要在您的允许散列中有一个下载变量。

Uploads.allow({
  insert:function(userId,project){
    return true;
  },
  update:function(userId,project,fields,modifier){
   return true;
  },
  remove:function(userId,project){
    return true;
  },
  download:function(){
    return true;
  }
});

关于javascript - CollectionFS 访问被拒绝 403 错误 #Meteor JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26136850/

相关文章:

javascript - 为什么我必须调用 () push() JS 函数并重新设置它以获得预期的结果?

javascript - 如何在 Haxe (JavaScript) 中加载和绘制 png 图像?

javascript - 使用 javascript 更新浏览器缓存

javascript - 如何在 React 中处理对 setState 的异步调用?

mongodb - 在 MongoDB 的 RAM 中保存一些集合

javascript - Meteor 1.3 中 "inProgress-team/react-native-meteor"的响应式使用

c++ - Qt 应用程序中的 MongoDB C++ 驱动程序稳定分支崩溃

c# - MongoDB C#Driver 响应。林克 : query for unique instances and using static AsQueryable Properties

node.js - 使用 Node 的 Mongodb find() 不返回所有文档(奇怪的行为)

mongodb - Mongo $OR 嵌套在 $AND 中