Using CollectionFS how can the url of a image be returned after upload?


#1

I am trying to return the url of the uploaded image and make it equal to uploadedurl. This is all in a function that is triggered when a photo is dropped into the upload box. uploadedurl is currently being set to undefined and returning is this error The provided value ‘undefined’ is not a valid enum value of type XMLHttpRequestResponseType. in the client console. What did I do wrong?

  var user = Meteor.user();
  var uploadedurl;

  FS.Utility.eachFile(e, function(file) {
      var newFile = new FS.File(file);
      newFile.userId = user._id;
      newFile.submitted= new Date();
      newFile.admin = Meteor.user().admin;

      Images.insert(newFile, function (error, fileObj) {
          if (error) {/*do something*/} else {
              var isuploaded = function(){
                if(fileObj.uploaded === true){
                  uploadedurl = fileObj.url();
                } else {
                  setTimeout(isuploaded, 500);
                }
              }
              isuploaded();
          }
      });
  });