gpt4 book ai didi

javascript - Firebase 存储错误 : 404 - ACCESS_BUCKET

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

我正在尝试将图像上传到 Firebase 存储。当我尝试上传图片时,出现 404 错误,但我已经在 firebase 中创建了存储。

Firebase npm 版本:firebase": "^7.24.0

错误:

code: 404
message: "Not Found. Could not access bucket \"<project>.appspot.com\""
status: "ACCESS_BUCKET"

存储规则:

rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}

Firebase 初始化:

const app = firebase.initializeApp({
apiKey: process.env.REACT_APP_FIREBASE_KEY,
authDomain: process.env.REACT_APP_FIREBASE_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID,
measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID
});

export const analytics = app.analytics();
export const storage = firebase.storage();
export default app;

服务JS:

export async function uploadImageCloud(image){
const storageRef = storage.ref("image/" + image.name);
return storageRef.put(image);
}

上传功能:

function uploadImage(){
setDataImageUploading(true);
uploadImageCloud(getDataImage).then((data)=>{
console.log(data);
setDataImageUploading(false);
}).catch((e)=>{
console.log(e);
setDataImageUploading(false);
});
}

知道我哪里搞砸了吗?

最佳答案

我遇到了同样的问题,最后我发现传递给 initializeAppstorageBucket 的值是非常敏感的数据。它应该完全顶级文件中的存储桶名称(没有 gs://):

enter image description here

例如在这个项目中它是steem-engine-dex.appspot.com

const app = firebase.initializeApp({
//...
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
//...
});

重要:

  • storageBucket 区分大小写。例如steem-engine-dex.appSpot.com 无效

  • storageBucket 不应在开头或结尾包含任何额外空间。例如steem-engine-dex.appspot.com steem-engine-dex.appspot.com 无效

关于javascript - Firebase 存储错误 : 404 - ACCESS_BUCKET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68344001/

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