首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在本地主机中通过Google Cloud使用Meteor的Slingshot包时出错

在本地主机中通过Google Cloud使用Meteor的Slingshot包时出错
EN

Stack Overflow用户
提问于 2016-08-16 02:23:55
回答 1查看 168关注 0票数 8

我试图在我的网站上设置一个小上传部分,让用户上传个人资料图像。我在Google Cloud中使用Slingshot,并从localhost测试,但我收到以下错误:

代码语言:javascript
复制
OPTIONS https://mybucket.storage.googleapis.com/ net::ERR_INSECURE_RESPONSE

我认为这个错误是由于我的CORS配置造成的,所以我尝试了各种不同的设置,但都没有效果。

这是我最新的CORS设置:

代码语言:javascript
复制
[
    {
      "origin": ["http://localhost:3000/"],
      "responseHeader": ["Content-Type"],
      "method": ["GET", "HEAD", "DELETE"],
      "maxAgeSeconds": 3600
    }
]

我也是这样尝试的:

代码语言:javascript
复制
[
    {
      "origin": ["*"],
      "responseHeader": ["*"],
      "method": ["GET", "HEAD", "DELETE"],
      "maxAgeSeconds": 3600
    }
]

还是什么都没有。和以前一样的错误。

这是我的Slingshot服务器代码:

代码语言:javascript
复制
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;
    }

});
}

客户端上传初始化如下:

代码语言:javascript
复制
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);
  }

所有的变量都检查出来了。我的pem文件已检出,并且工作正常。因此,无论是Google Cloud还是我设置CORS文件的方式都存在错误。

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-03-26 12:35:56

我在这里也遇到了同样的问题,但调试要糟糕得多。在我的Android应用程序中,上传工作正常,但在iOS中,我得到了同样的错误。

CNAME:不要在存储桶名称中使用圆点(作为别名)。当从gs://static.myapp.com重命名为gs://myapp-static时,我的工作正常。如果需要自定义域名,请使用手动负载均衡器。

完整故事

我的存储桶被命名为static.myapp.com,这样我就可以在我的域名服务提供商中创建一个CNAME记录,并使用自定义域提供我的镜像。

原来上传本身是通过带有通配符*.storage.googleapis.com的SSL证书的url https://<bucket-name>.storage.googleapis.com进行的,所以我被迫将存储桶重命名为myapp-static,以便URL与证书相匹配。

这打破了CNAME方法,但您仍然可以设置手动负载均衡器来隐藏Google Cloud URL并使用自定义子域。下面是我当前负载均衡器配置的屏幕截图。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38960728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档