Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 error when trying to upload from Meteor using slingshot package #70

Closed
ghost opened this issue Feb 19, 2015 · 6 comments
Closed

500 error when trying to upload from Meteor using slingshot package #70

ghost opened this issue Feb 19, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Feb 19, 2015

I have a javascript file in the server side that looks like this

Slingshot.GoogleCloud.directiveDefault.GoogleSecretKey = Assets.getText('google-cloud-service-key.pem');


Slingshot.createDirective("myFileUploads", Slingshot.GoogleCloud, {
  bucket: "enwave",
  GoogleAccessId: "randomID",

 authorize: function () {
   //Deny uploads if user is not logged in.
   if (!this.userId) {
     var message = "Please login before posting files";
     throw new Meteor.Error("Login Required", message);
   }

   return true;
 },

 key: function (file) {

   //Store file into a directory by the user's username.
   var user = Meteor.users.findOne(this.userId);
   return user.username + "/" + file.name;
 }
});

I have this on my client side

'change #fileUpload':function(event, template){
      //evt.preventDefault();
      var file = event.currentTarget.files[0];
      console.log(file);

      var uploader = new Slingshot.Upload("myFileUploads");
      uploader.send(document.getElementById('fileUpload').files[0], function (error, downloadUrl) {
      Meteor.users.update(Meteor.userId(), {$push: {"profile.files": downloadUrl}


      });

      });

    }

I have this in my lib folder

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

and in /private folder I have a google-cloud-service-key.pem file that I converted after downloading from google cloud.

I get this error when choosing a image in the file upload input

 POST https://enwave.storage.googleapis.com/ 500 (OK)
debug.js:41 update failed: Access denied

I must be doing something wrong, google says a 500 error in google cloud is a internal server error, but I must be doing something wrong, I highly doubt it is on googles end. I am also testing off of localhost if that might be it.

Thanks in Advance for any help.

After log the error in the console, this is what I get

https://i.stack.imgur.com/pffI4.png

@gsuess
Copy link
Contributor

gsuess commented Feb 19, 2015

It is being denied by google, not by slingshot. Please click on the POST request in your browsers dev tools to inspect the XML response that you get from google. It should contain more details about why it is being rejected.

@ghost
Copy link
Author

ghost commented Feb 19, 2015

This is the XML Response
InternalErrorWe encountered an internal error. Please try again.

ABCemsqA/49FPwB5u877Jt1vyodMFYvQo+Nxba9L+54t4n31W5StGcfiL1/DfhrzuGEfhi63U6j3 5WYQxoYPL5T9xNaFkuX9Hg...

@ghost
Copy link
Author

ghost commented Feb 19, 2015

This is what the header returns

Remote Address:74.125.25.132:443
Request URL:https://enwave.storage.googleapis.com/
Request Method:POST
Status Code:500 OK
Request Headers
:authority:enwave.storage.googleapis.com
:method:POST
:path:/
:scheme:https
accept:*/*
accept-encoding:gzip, deflate
accept-language:en-US,en;q=0.8
content-length:59584
content-type:multipart/form-data; boundary=----WebKitFormBoundaryjW0KMAtnvqnxsY7u
origin:https://localhost:3000
referer:https://localhost:3000/submit
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36
x-client-data:CI62yQEIpLbJAQiptskBCMS2yQEI6ojKAQieksoBGKuJygE=
Request Payload
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="key"

minimize.jpeg
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="bucket"

enwave
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="Content-Type"

image/jpeg
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="Content-Disposition"

inline; filename="minimize.jpeg"
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="GoogleAccessId"

00b4903a977a9b1f9ad3c9f1f3785afdc1af228104554ee6fce967a7899eb208
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="policy"

eyJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMCw1ODEyMl0seyJrZXkiOiJtaW5pbWl6ZS5qcGVnIn0seyJidWNrZXQiOiJlbndhdmUifSx7IkNvbnRlbnQtVHlwZSI6ImltYWdlL2pwZWcifSx7IkNvbnRlbnQtRGlzcG9zaXRpb24iOiJpbmxpbmU7IGZpbGVuYW1lPVwibWluaW1pemUuanBlZ1wiIn1dLCJleHBpcmF0aW9uIjoiMjAxNS0wMi0xOVQxNzoxNzoxMy43MThaIn0=
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="signature"

QmiNNCDxvbYvZ8X27dCsj4OjvSj4zzIcb3pWuo6qP+10mo9TkaUTgc1Su8EbAW04OtZtZr2Uiohf8S5bIiEqbUBQS8bknFszysTvTQSSOD4DsZM6dNP6iZ5Ukd9Qboc3aoAH5WOJCKxRnxJVdOM6NTr4W5V5SSXtgooHKWrOTIA=
------WebKitFormBoundaryjW0KMAtnvqnxsY7u
Content-Disposition: form-data; name="file"; filename="minimize.jpeg"
Content-Type: image/jpeg


------WebKitFormBoundaryjW0KMAtnvqnxsY7u--
Response Headers
access-control-allow-origin:*
access-control-expose-headers:Content-Length, Content-Type, Date, Server, Transfer-Encoding
alternate-protocol:443:quic,p=0.08
content-length:5196
content-type:application/xml; charset=UTF-8
date:Thu, 19 Feb 2015 17:12:14 GMT
server:UploadServer ("Built on Feb 9 2015 19:54:00 (1423540440)")
status:500

@gsuess
Copy link
Contributor

gsuess commented Feb 19, 2015

Clearly a Google Cloud Storage issue.

@ghost
Copy link
Author

ghost commented Feb 19, 2015

Ok I keep looking into my bucket setup I guess.

@ghost
Copy link
Author

ghost commented Feb 19, 2015

Turns out I was using the wrong GoogleAccessId I was using the Google Cloud Storage ID when what ended up working was the email address in the client id section under api credentials seen here https://cloud.google.com/storage/docs/authentication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant