title: Meteor CollectionFS: Make sure the image is uploaded before displaying
body: <p>I am using the <a href="https://github.com/CollectionFS/Meteor-CollectionFS" rel="nofollow">CollectionFS</a> package with the S3 adapter and I've looked at a few different solutions but cannot get this to work right. </p>
  
  <p>The problem: Even though the file/image is being uploaded to S3 successfully, the callback for a successful upload is triggered before it is safe to display the image. This causes a broken image to be displayed sometimes. </p>
  
  <p>I found out about the <code>fileObj.once("uploaded", function(){})</code> callback but it seems "uploaded" basically means sending the image to the server. The S3 uploading does not happen by then. A temporary workaround I found is to just to just have <code>setTimeout</code> for 3-4 seconds but this is not reliable. </p>
  
  <p>Here is my upload code: </p>
  
  <pre><code>FS.Utility.eachFile(event, function(file) {
      Session.set('profilePhotoUploaded', false);
      var newFile = new FS.File(file);
      newFile.metadata = {owner: Meteor.userId()};    
  
      ProfileImages.insert(newFile, function (err, fileObj) {
        if (err){
           console.log("error! - " + err);
        } else {
           // handle success depending what you need to do
  
          var userId = Meteor.userId();
  
          // This does NOT run when image is stored in S3. I think it runs when the image reached the app server.
          fileObj.once("uploaded", function () {
  
              // timeout of 3 seconds to make sure image is ready to be displayed 
              // --- This is not a good solution and it image does is not always ready
              setTimeout(function(){ 
                  var uploadedImage = {
                    "profile.image.url": "/cfs/files/profileImages/" + fileObj._id
                  };
                  Meteor.users.update(userId, {$set: uploadedImage});
  
                  Session.set('profilePhotoUploaded', true);
              }, 3000);  
  
              console.log("Done uploading!");
          });
       }
     });
  });
  </code></pre>
  
  <p>Is there a different callback to check if the image has actually been stored in S3? I tried <code>fileObj.once("stored", function(){})</code> but that does not work.</p>