如何将自动形式的图像链接到CollectionFS中的用户集合以显示个人资料图片?

时间:2015-06-05 19:22:54

标签: javascript mongodb meteor meteor-autoform

使用autoform我保存了他们上传到“images”集合中的用户个人资料照片。但是我不知道如何调用要在模板上加载的特定图片。以下内容不会在模板上显示图像。但是,如果我将Images.find({'doc.metadata.ownerId':Meteor.userId()});更改为Images.find(),则会加载所有图片,但我无法指定我想要的图片。

this.Images = new FS.Collection("Images", {
  stores: [new FS.Store.GridFS("Images", {})]
});

Images.files.before.insert(function(doc) {
  doc.metadata = {
    date: Date.now(),
    ownerId: this.userId
             };
  console.log("before", doc);
  return doc;
});

Template.photos.helpers({
      Images: function () {
        Images.find({'doc.metadata.ownerId':Meteor.userId()});
                }
     });

2 个答案:

答案 0 :(得分:1)

这个怎么样:

Template.photos.helpers({
  Images: function () {
    Images.find({'metadata.ownerId':Meteor.userId()});
  }
});

答案 1 :(得分:1)

您正在做的是用户上传的图像,您将userid添加为元值并存储它。它只会让您获取用户上传的所有图像。由于您还使用了时间戳,因此最新的时间戳将是最新的个人资料图片。

或者,在用户文档中,将photo字段添加到profile

这样,当用户上传照片时,将photo值设置为已上传图片的键并显示照片,即可进行

Images.findOne({ _id: Meteor.user().profile.photo })

如果您使用autoform,profile.photo中的存储图像ID将更加容易。

希望这有帮助。

相关问题