简体   繁体   English

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

[英]CollectionFS access denied 403 error #Meteor JS

I am using collectionFS for file upload, my code is bellow. 我正在使用collectionFS进行文件上传,代码如下。 Logged user can insert image to images collection, also I can see that file is uploaded on server. 登录的用户可以将图像插入图像集合,也可以看到该文件已上传到服务器上。 Image links and download button is displaying before remove insecure package able to see images and download. 在删除不安全的程序包之前,将显示图像链接和下载按钮,以便查看图像并下载。 After removed insecure package from project. 从项目中删除不安全的程序包后。 Images are not displaying also download is not working(can retrieve image name and url), receiving access denied 403 error. 图片未显示,也无法下载(可以检索图片名称和网址),收到访问被拒绝的403错误。 What I really wanted is that signed user can insert files to server and everyone can see images, also able to download files.I wrote allow rules and also publish and subscribe. 我真正想要的是签名的用户可以将文件插入服务器,每个人都可以看到图像,也可以下载文件。我编写了允许规则,还发布和订阅了。 What is the problem here? 这里有什么问题?
js file 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 file 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>

If you have insecure and autopublish turned off, and you access your files through a subscription, I believe you just need a download var in your allow hash. 如果您不安全且自动发布已关闭,并且您通过订阅访问文件,那么我相信您只需要在allow哈希中下载var。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM