How to change image into thumbnail in MeteorJS with collectionfs

492 Views Asked by At

Using one of the comments/answers I fixed the photo viewing, however it does not load sometimes if the image is too big. It would be great to see an example of code to turn an image into a thumbnail.

<template name="photos">
    <form>
        <input id="file" type="file">
        <input id="addFile" type="submit">
    </form>

    {{#each images}}
      <div>
         <a href="{{this.url}}" target="_blank"><img src="{{this.url store='images' uploading='/images/uploading.jpg' storing='/images/storing.jpg'}}" alt="" class="thumbnail" /></a>
      </div>
    {{/each}}

</template>

Javascript:

if (Meteor.isServer) {
  // Create server database for listings
  var Images = new FS.Collection("images", {
    stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
  });

    Template.photos.events({
      'click #addFile' : function(e, t){
        var file = t.find('#file').files[0];
        var ticket = this._id;
        var newFile = new FS.File(file);
        newFile.metadata = {
          ticketId: ticket
        };
        Images.insert(newFile, function (err, fileObj) {
          if (!err) {
            console.log(fileObj);
          }
        });
       }
    });

    Template.photos.helpers({
      images: function () {
        return Images.find(); // Where Images is an FS.Collection instance
      }
    });
}
0

There are 0 best solutions below