2014-12-07 4 views
0

안녕하세요 저는 Meteor에서 새로 왔으며 간단한 파일/이미지 업로드/다운로드를 개발하려고합니다.Meteor 이미지를 업로드 할 수 없습니다.

내 코드와 패키지 :

meteor create testApp 
meteor add cfs:standard-packages 
meteor add cfs:filesystem 

testApp.js :

YourFileCollection = new FS.Collection("yourFileCollection", { 
      stores: [new FS.Store.FileSystem("yourFileCollection", {path: "~/meteor_uploads"})] 
     }); 
if (Meteor.isClient) { 
     // counter starts at 0 
    Template.yourTemplate.events({ 
     'change .your-upload-class': function(event, template) { 
      FS.Utility.eachFile(event, function(file) { 
       var yourFile = new FS.File(file); 
       yourFile.creatorId = Meteor.userId(); // add custom data 
       YourFileCollection.insert(yourFile, function (err, fileObj) { 
        if (!err) { 
         // do callback stuff 
        } 
       }); 
      }); 
     } 
    }); 
    } 

    if (Meteor.isServer) { 
     YourFileCollection.allow({ 
      insert: function (userId, doc) { 
       return !!userId; 
      }, 
      update: function (userId, doc) { 
       return doc.creatorId == userId 
      }, 
      download: function (userId, doc) { 
       return doc.creatorId == userId 
      } 
     }); 
    } 

및 HTML :

<head> 
    <title>protoSonn</title> 
</head> 

<body> 
    <h1>Welcome to Meteor!</h1> 

    {{> yourTemplate}} 
</body> 

<template name="yourTemplate"> 
    <input class="your-upload-class" type="file"> 
</template> 

내/TestApp가/공용 폴더에도 두 이미지를 . 내 공용 폴더에서 이미지를 선택한 후 확인을 클릭하십시오. 아무것도 일어나지 않는다. mongodb에서 생성 된 콜렉션이 없습니다. 뭐가 문제 야?

답변

0

먼저 난 당신이 계정 패키지를 사용하여 인증되지 않은보고 당신으로 인해 계정 패키지하지 포함에 obvivious 작동하지 않을 것이다, 당신 수집에 Meteor.userId()을 포함하고 두 번째는 규칙을 허용/거부 한 불필요한

우선/간단한 솔루션 : 제거 다음 코드

yourFile.creatorId = Meteor.userId(); // add custom data 

에서 선 허용/거부 규칙

if (Meteor.isServer) { 
     YourFileCollection.allow({ 
      insert: function (userId, doc) { 
       return !!userId; 
      }, 
      update: function (userId, doc) { 
       return doc.creatorId == userId 
      }, 
      download: function (userId, doc) { 
       return doc.creatorId == userId 
      } 
     }); 
    } 
다음

는 유성 ​​패드에서 코드를 작동 : 업로드 한 후 http://bit.ly/1u8gpOq
, 개발 콘솔 검사에서 파일을 다음과 같이

YourFileCollection.find().fetch() 

- 명령

두 번째 솔루션 :

그래서 계정 패키지와 응용 프로그램에 대한 인증을 포함, Meteor.userId() 값을 얻고 그 후에 업로드 화면을 보여줄 것입니다.

관련 문제