Error using Meteor Slingshot with Google Cloud from localhost

I am trying to set up a small download section on my website so that the user can upload a profile image. I use Slingshot with Google Cloud and test this with localhost, but I get the following errors:

OPTIONS https://mybucket.storage.googleapis.com/ net::ERR_INSECURE_RESPONSE 

enter image description here

I believe this error is related to my CORS configuration, so I tried all sorts of settings and nothing works.

This is my last installation of CORS:

 [ { "origin": ["http://localhost:3000/"], "responseHeader": ["Content-Type"], "method": ["GET", "HEAD", "DELETE"], "maxAgeSeconds": 3600 } ] 

I also tried this:

 [ { "origin": ["*"], "responseHeader": ["*"], "method": ["GET", "HEAD", "DELETE"], "maxAgeSeconds": 3600 } ] 

However, nothing. Same mistake as before.

This is my server code for Slingshot:

 if(Meteor.isServer){ // Initiate file upload restrictions Slingshot.fileRestrictions("userLogoUpload", { //Only images are allowed allowedFileTypes: ["image/png", "image/jpeg", "image/gif"], //Maximum file size: maxSize: 2 * 1024 * 1024 // 2 MB (null for unlimited) }); // Google Cloud Directives Slingshot.createDirective("userLogoUpload", Slingshot.GoogleCloud, { bucket: Meteor.settings.public.GoogleCloudBucket, GoogleAccessId: Meteor.settings.private.GoogleAccessId, GoogleSecretKey: Assets.getText("xxxxxxxxxx.pem"), // Uploaded files are publicly readable acl: "public-read", authorize: function(){ if(!Meteor.userId()){ throw new Meteor.error("Login Required", "Please log in to upload files"); } return true; }, key: function(file){ let user = Meteor.users.findOne(Meteor.userId()); return user.profile.username + "/" + file.name; } }); } 

Here's the client side init initiation:

 let uploader = new Slingshot.Upload("userLogoUpload"); uploader.send(document.getElementById("upload").files[0], function(error, downloadUrl){ if(!error){ console.log(downloadUrl); } else{ console.error('Error uploading', uploader.xhr.response); console.log(error); } 

All variables are checked. My pem file is checked and works fine. So there should be a bug with Google Cloud or with the way I configured my CORS file.

Any help would be appreciated.

+7
meteor meteor-slingshot
source share
1 answer

I had the same problem, but debugging was much worse. In my Android application, the download worked fine, but in iOS I got the same error.

TL; DR: Do not use periods in the name of your bucket (for the CNAME alias). Mine worked when renaming from gs://static.myapp.com to gs://myapp-static . If a custom domain is required, use a manual load balancer.



Full story

My bucket was called static.myapp.com , so I could create a CNAME record in my DNS provider and serve my images using a custom domain.

Turns off loading via the https://<bucket-name>.storage.googleapis.com with an SSL certificate for the *.storage.googleapis.com , so I had to rename the bucket to myapp-static so that the URL matches the certificate.

This violates the CNAME approach, but you can configure a manual load balancer to hide the Google Cloud URL and use your own subdomain. Below is a screenshot for my current load balancing configuration.

enter image description here

+1
source share

All Articles