gpt4 book ai didi

meteor - 从本地主机将 Meteor 的 Slingshot 包与 Google Cloud 一起使用时出错

转载 作者:行者123 更新时间:2023-12-04 12:52:30 24 4
gpt4 key购买 nike

我正在尝试在我的网站上设置一个小的上传部分,供用户上传个人资料图片。我正在将 Slingshot 与 Google Cloud 结合使用并从本地主机进行测试,但出现以下错误:

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

enter image description here

我认为这个错误是因为我的 CORS 配置,所以我尝试了各种不同的设置,但没有任何效果。

这是我最近的 CORS 设置:
[
{
"origin": ["http://localhost:3000/"],
"responseHeader": ["Content-Type"],
"method": ["GET", "HEAD", "DELETE"],
"maxAgeSeconds": 3600
}
]

我也这样试过:
[
{
"origin": ["*"],
"responseHeader": ["*"],
"method": ["GET", "HEAD", "DELETE"],
"maxAgeSeconds": 3600
}
]

依然没有。和以前一样的错误。

这是我的 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;
}

});
}

这是客户端上传启动:
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 文件 check out 并且工作正常。因此,谷歌云或我设置 CORS 文件的方式一定有错误。

任何帮助,将不胜感激。

最佳答案

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

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

全文

我的存储桶被命名为 static.myapp.com所以我可以在我的 DNS 提供商中创建一个 CNAME 记录并使用自定义域提供我的图像。

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

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

enter image description here

关于meteor - 从本地主机将 Meteor 的 Slingshot 包与 Google Cloud 一起使用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com