Meteor CollectionFS正在获取图像文件的url

Meteor CollectionFS正在获取图像文件的url,meteor,collectionfs,Meteor,Collectionfs,Hi-am使用CollectionFS上载和存储图像 上载和存储文件成功。我可以从发布中检索文件对象。但我无法获取文件的URL。我需要img标签的url 下面是我如何声明集合的 Images = new FS.Collection("images", { stores: [new FS.Store.GridFS("images")] }); 在浏览器控制台中,以下代码返回FS.File对象 NewsImages.find().fetch()[0] FS.File {createdByT

Hi-am使用CollectionFS上载和存储图像

上载和存储文件成功。我可以从发布中检索文件对象。但我无法获取文件的URL。我需要
img
标签的url

下面是我如何声明集合的

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…}
但url返回null

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.

我用
this.userId
替换了
Meteor.userId()
,但是
this.userId
未定义。

在保存图像时使用回调,然后将图像id放入另一个 收集粗略的伪代码

Images.insert(yourFsFile, function (error, fileObj) {
    if (error) {
      // cry!
    }

    _.extend(yourItem, {imageId: fileObj._id});

    Meteor.call('otherCollectioInsert', yourItem, function(error, result) {
      if (error) {
        // cry again!
      }
      // should have saved the image id so you can use the url
      // http://www.you.com/cfs/files/images/the_id_you_saved
    });
  });

我希望这有助于尝试指定的方法。在使用URL检索图像时,我收到403条禁止的消息。我是否应该添加任何安全规则?我认为在将图像加载到存储中时,您可能需要超时或使其处于反应状态。