最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CollectionFS access denied 403 error #Meteor JS - Stack Overflow

programmeradmin3浏览0评论

I am using collectionFS for file upload, my code is bellow. 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. 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

    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

    <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>

I am using collectionFS for file upload, my code is bellow. 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. 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

    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

    <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>
Share Improve this question asked Oct 1, 2014 at 8:07 zevsuldzevsuld 2764 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 19

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.

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;
  }
});
发布评论

评论列表(0)

  1. 暂无评论