2014-10-01 2 views
7

파일 업로드에 collectionFS를 사용하고 있습니다. 로그 된 사용자는 이미지 컬렉션에 이미지를 삽입 할 수 있으며 해당 파일이 서버에 업로드 된 것을 볼 수 있습니다. 이미지 링크 및 다운로드 버튼은 이미지를보고 다운로드 할 수있는 안전하지 않은 패키지를 제거하기 전에 표시됩니다. 프로젝트에서 안전하지 않은 패키지를 제거한 후 이미지가 표시되지 않습니다. 다운로드가 작동하지 않습니다 (이미지 이름과 URL을 검색 할 수 있음). 액세스 거부 403 오류가 발생했습니다. 내가 정말로 원했던 것은 서명 된 사용자가 서버에 파일을 삽입 할 수 있고 모든 사람이 파일을 다운로드 할 수있는 이미지를 볼 수 있다는 것입니다. 나는 허용 규칙을 작성하고 게시 및 구독도했습니다. 여기에 어떤 문제가 있습니까?
JS 파일CollectionFS 액세스가 거부되었습니다. 403 오류 #Meteor 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; 
    } 
    }); 

당신이 불안 가지고 autopublish가 꺼져, 당신은 가입을 통해 파일을 액세스하는 경우

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

답변

18

, 당신이 당신의 수 해시 다운로드 VAR을 필요로 생각 html 파일 .

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

답장을 보내 주셔서 감사합니다. BTW MeteorJS에 대한 youtube 비디오를 보았습니다. 아주 좋은 튜토리얼이었습니다. 페이지 매김 튜토리얼은 매우 유용했습니다. 다시 프로젝트에 사용했습니다. :) – zevsuld

+0

방금이 같은 문제가 발생했습니다. 수정 해 주셔서 감사합니다! – CodeChimp

관련 문제