1
您好,我正在使用CollectionFS上傳和存儲圖像。CollectionFS獲取映像文件的url
上傳和存儲文件成功。我可以從發佈中檢索文件對象。但我無法獲取文件的URL。我需要URL爲img
標記
以下是我如何聲明集合。
Images = new FS.Collection("images", {
stores: [new FS.Store.GridFS("images")]
});
在下面的代碼瀏覽器控制檯返回FS.File對象
NewsImages.find().fetch()[0]
FS.File {createdByTransform: true, _id: "3kqLZRdLD33dKir2M", original: Object, chunkSize: 2097152, chunkCount: 0…}
但網址傳回空。
NewsImages.find().fetch()[0].url()
null
是否需要額外的工作來生成URL?
更多詳細信息
我使用下面允許規則。
NewsImages.allow({
//more others
download: function(){
if(Meteor.userId()){
return true;
}else{
return false;
}
}
});
我收到以下異常。
Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
我換成Meteor.userId()
與this.userId
但this.userId
是不確定的。
試過指定的方法。使用URL檢索圖像時,我得到403禁止消息。我應該添加任何安全規則嗎? –
我想你可能需要暫停或在圖像被加載到商店時使其處於被動狀態。 – LongWalks