Meteor-files: .link("thumbnail") displays original while thumbnail is not yet created, but won麓t switch to thumb afterwards

Created on 6 Apr 2017  路  3Comments  路  Source: veliovgroup/Meteor-Files

I麓m facing a smaller issue when uploading images and creating thumbnails.

In my template helper I麓m using this code to fetch the thumbnail

 thumbnail: function () {
            return Collections.Files.findOne({_id: this._id}).link('thumbnail');
        }

The problem is, it displays the original according to the documentation, when the thumbnail doesn麓t exist, which is the case right after the upload. My problem is now, that after I麓ve created the tumbnail, I update the collection, but the image doesn麓t change to thumbnail. I need to reload the whole page first.

What is the best way to refresh it/make link() reactive?

Most helpful comment

Hello @Mklueh

The best way is to wait for thumbnail is to be created, here is snippet taken from demo app:

{
  thumbnail: function () {
    const img = Collections.AppFiles.findOne({_id: this._id};
    if (img.versions.thumbnail) {
      // Return thumbnail
      return img.link('thumbnail');
    } else {
      // Return temporary placeholder
      return '/img/some-image-placeholder.jpg';
    }
  }
}

Hope you've got the main idea from snippet above.
Let me know if this approach fits your needs.

All 3 comments

Hello @Mklueh

The best way is to wait for thumbnail is to be created, here is snippet taken from demo app:

{
  thumbnail: function () {
    const img = Collections.AppFiles.findOne({_id: this._id};
    if (img.versions.thumbnail) {
      // Return thumbnail
      return img.link('thumbnail');
    } else {
      // Return temporary placeholder
      return '/img/some-image-placeholder.jpg';
    }
  }
}

Hope you've got the main idea from snippet above.
Let me know if this approach fits your needs.

Thank you for the fast response.

Works for me ;)

@Mklueh ,

I'm glad this solved your issue.

Please, support this project by:

Was this page helpful?
0 / 5 - 0 ratings