sylvaingi / meteor-smartfile

MIT License
10 stars 3 forks source link

Displaying images to users #8

Closed CiaraBurkett closed 10 years ago

CiaraBurkett commented 10 years ago

Thanks so much for the smart package! I'm able to upload images to a subdirectory called "uploads," and now I'm looking to display the images to the public.

I've tried using sf.onUpload results.path to return the relative path to the client, but the link doesn't display. Then I tried this: (Converted the code from CoffeeScript, apologies in advance.)

var sf;

sf = new SmartFile({
  publicRootUrl: "https://file.ac/2ewsByMDlIQ/"
});

Template.newManga.events({
  "submit form": function(e) {
    var manga;
    e.preventDefault();
    manga = {
      coverInput: $('#cover').get(0).files[0],
      cover: $(e.target).find("[name=cover]").val(),
      title: $(e.target).find("[name=title]").val(),
      author: $(e.target).find("[name=author]").val(),
      description: $(e.target).find("[name=description]").val()
    };
    sf.upload(manga.cover, function(err, result) {
      manga.cover.reset();
      console.log("Upload public URL:" + sf.resolvePublic(result));
    });
    return Meteor.call("manga", manga, function(error, id) {
      if (error) {
        return alert(error.reason);
      }
      Router.go("mangaPage", {
        _id: id
      });
    });
  }
});

Which returns this:

screenshot 2014-03-12 10 24 19

Thanks again! Also wondering if displaying images should be an option in the package itself?

sylvaingi commented 10 years ago

(I've taken the liberty to edit your issue for readability, surround your code with triple backslashes to turn on syntax highlighting)

You might have an error returned in the upload callback, I've updated the example to add explicit error handling: https://github.com/sylvaingi/meteor-smartfile-example/blob/master/client/client.js.

If something went wrong now an error should appear in the console.

CiaraBurkett commented 10 years ago

Thanks! I fixed the upload callback and now the URL displays in the console.