Can't get Meteor slingshot to work


#1

I am trying to get slingshot to work but having a hard time, I am attaching here the code I have.

The error I get n the console is:

“Exception in delivering result of invoking ‘slingshot/uploadRequest’: TypeError: Cannot read property ‘response’ of undefined”

client

Template.hello.events({
    'change .uploadFile': function(event, template) {

      event.preventDefault();

var uploader = new Slingshot.Upload("myFileUploads");

uploader.send(document.getElementById('uploadFile').files[0], function (error, downloadUrl) {
  if (error) {
    // Log service detailed response
    console.error('Error uploading', uploader.xhr.response);
    alert (error);
  }
  else{
    console.log("Worked!");
  }

  });
}
});

lib

Slingshot.fileRestrictions("myFileUploads", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
  maxSize: null // 10 MB (use null for unlimited)
});

server

Slingshot.fileRestrictions("myFileUploads", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
  maxSize: null,
});


    Slingshot.createDirective("myFileUploads", Slingshot.S3Storage, {
      AWSAccessKeyId: "my-AWSAccessKeyId",
      AWSSecretAccessKey: "my-AWSSecretAccessKey",
      bucket: "slingshot-trial-2",
      acl: "public-read",

      authorize: function () {
        //Deny uploads if user is not logged in.

        },
      key: function (file) {
        //Store file into a directory by the user's username.
        return file.name;
      }

    });

#2

I think you must set a region as well.


#3

@jamgold still won’t work


#4

You are trying to read uploader.xhr.response which does not exist


#5

What does the ‘alert’ tell you? As that is where you’re printing the actual error.


#6

@cstrat at the end I mnaged to get it to work , I believe it was not adding return true to the authorize function.


#7

Hello - can you clarify? What was the solution?


#8

I’ve got this to work but with React :wink: If you’re still having issues I can help.


#9

What was the solution? I had this working at one point, but it just seemed to have intermittently broken with this error. I have the return true in the authorize.

Edit: In my case, I was trying to upload a .gif but I only allowed .jpg and .png!!

Error message is really unhelpful! :stuck_out_tongue: