2013-09-16 2 views
1

유성과 collectionfs를 사용하는 프로젝트에서 작업하고 있습니다.collectionfs는 다운로드 URL을 생성합니다.

파일을 collectionfs에 업로드하고 파일 핸들러를 제자리에 두었습니다. {{cfsFileUrl "defaultFilehandler"}}

핸들러 도우미를 사용하면 이미지가 저장되는 URL을 표시 할 수 있지만이 URL에서 이미지를 다운로드 할 수는 없습니다. 나는 두 가지를 달성하고자하는 궁극적

: (3000 내가 로컬 호스트를 writen 것처럼) : 유성 페이지

localhost:3000/cfs/contacts/Nj3WzrBKhqd9Mc9NP_defaultHandler.png 

유성 경로 나이 : 내 브라우저에 복사

1

표시하는 HTML 태그를 사용하여 이미지 :

0123을

두 번째 사용자가이 이미지를 볼 수 있도록 허용하고 싶습니다.

'download-url'을 사용하면 보안 성이 충분하지 않습니다.

클라이언트 JS

ContactsFS = new CollectionFS('contacts', { autopublish: false }); 

Deps.autorun(function() { 
    Meteor.subscribe('myContactsFiles'); 
}); 

Template.queueControl.events({ 
    'change .fileUploader': function (e) { 
     var files = e.target.files; 
     for (var i = 0, f; f = files[i]; i++) { 
      ContactsFS.storeFile(f); 
     } 
    } 
}); 

서버 JS

ContactsFS = new CollectionFS('contacts', { autopublish: false }); 

ContactsFS.allow({ 
    insert: function(userId, file) { 
     console.log('user'+userId+"file"+JSON.stringify(file)); 
     console.log("WILL SAVE:"+userId && file.owner === userId); 
     return userId && file.owner === userId; 
    }, 
    update: function(userId, files, fields, modifier) { 
     return _.all(files, function (file) { 
      return (userId == file.owner); 
     }); //EO iterate through files 
    }, 
    remove: function(userId, files) { return false; } 
}); 

Meteor.publish('myContactsFiles', function() { 
    if (this.userId) { 
     return ContactsFS.find({ owner: this.userId }, { limit: 30 }); 
    } 
}); 


ContactsFS.fileHandlers({ 
    default1: function(options) { // Options contains blob and fileRecord — same is expected in return if should be saved on filesytem, can be modified 
    return { blob: options.blob, fileRecord: options.fileRecord }; // if no blob then save result in fileHandle (added createdAt) 
    }}); 
+0

안녕하세요, 이미지를 표시 할 때 문제가 발생했습니다. "이미지로 해석되었지만 MIME 유형이 text/html로 전송 된 리소스 :"오류로 인해 깨진 이미지 아이콘이 나타납니다. 같은 문제에 직면 했습니까? – Junhao

답변

2

대답 1 :

당신에게 내가 collectionFS에서 정상 튜토리얼을 통해 갔다 지점에 도착하기 위해

collectionFS의 업데이트 된 0.3.3 버전을 사용하여 공개적으로 해당 파일을 액세스 가능하게 만들 수 있습니다. 또는 그들을보십시오. default1 당신이 ContactsFS.fileHandlers

대답 2에 정의 된 핸들러 함수의 이름입니다

<img src="{{cfsFileUrl 'default1'}}"> 

:

는 더 안전한 솔루션은 제작의 상점에서, 지금과 같은 collectionFS으로 구축하지 있습니다.

+0

제안 사항을 따르면 이미지 아이콘이 표시되지만 "이미지로 해석되었지만 MIME 유형으로 전송 된 리소스 text/html :"오류로 인해이 아이콘이 손상되었습니다. 어떤 생각을 어떻게 고쳐야 하는가? – Junhao

관련 문제