ユーザーがプロフィール画像をアップロードできるように、ウェブサイトに小さなアップロードセクションを設定しようとしています。Google Cloud で Slingshot を使用し、localhost からこれをテストしていますが、次のエラーが発生します。
OPTIONS https://mybucket.storage.googleapis.com/ net::ERR_INSECURE_RESPONSE
このエラーは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ファイルはチェックアウトし、正常に動作します。したがって、Google Cloud または CORS ファイルの設定方法にエラーがあるはずです。
どんな助けでも大歓迎です。