【问题标题】:CollectionFS access denied 403 error #Meteor JSCollectionFS 访问被拒绝 403 错误#Meteor JS
【发布时间】:2014-11-26 00:39:03
【问题描述】:

我正在使用 collectionFS 进行文件上传,我的代码如下。登录的用户可以将图像插入图像集合,我也可以看到该文件已上传到服务器上。图片链接和下载按钮在删除不安全的包之前显示,可以查看图片和下载。从项目中删除不安全的包后。图片不显示也下载不工作(可以检索图片名称和网址),接收访问被拒绝 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>

【问题讨论】:

    标签: javascript mongodb meteor


    【解决方案1】:

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

    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;
      }
    });
    

    【讨论】:

    • 谢谢你的回答,我真的想通了。顺便说一句,我看了你关于 MeteorJS 的 youtube 视频,这是非常好的教程,分页教程非常有用,我在我的项目中使用它,再次感谢 :)
    • 我刚刚遇到了同样的问题。感谢您的修复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 2017-04-30
    • 2016-08-22
    • 1970-01-01
    • 2023-03-16
    • 2017-01-10
    相关资源
    最近更新 更多