javascript - 尝试读取图像文件时,我不断从 Firebase 存储中收到 403
问题描述
我很难理解 Firebase 上传的整个令牌部分。
我想简单地上传使用头像,将它们保存到数据库中,然后在客户端读取它们。
const storageRef = firebase.storage().ref();
storageRef.child(`images/user-avatars/${user.uid}`).put(imageObj);
然后,在我的云函数中,我获取新的 url,如下所示:
exports.writeFileToDatabase = functions.storage.object().onFinalize(object => {
const bucket = defaultStorage.bucket();
const path = object.name as string;
const file = bucket.file(path);
return file
.getSignedUrl({
action: "read",
expires: "03-17-2100"
})
.then(results => {
const url = results[0];
const silcedPath = path.split("/");
return db
.collection("venues")
.doc(silcedPath[1])
.set({ images: FieldValue.arrayUnion(url) }, { merge: true });
});
});
我已IAM
在 Google APIs 平台中启用,并已添加Cloud functions service agent
到App Engine default service account
.
我觉得以前的配置完全相同,但现在有时它甚至不写新的 url,或者我得到 403 试图读取它。对于我做错的事情,我找不到任何解释或错误。
编辑:忘记添加这段代码,但FieldValue
在文档顶部设置为
const FieldValue = admin.firestore.FieldValue;
编辑:这是我得到的确切错误Failed to load resource: the server responded with a status of 403 ()
当我尝试使用这个由上面的函数自动生成的链接作为图像组件的来源时,我得到了它:
https://storage.googleapis.com/frothin-weirdos.appspot.com/images/user_avatars/yElCIVY4bAY5g5LnoOBhqN6mDNv2?GoogleAccessId=frothin-weirdos%40appspot.gserviceaccount.com&Expires=1742169600&Signature=qSqPuuY4c5xmdnpvfZh39Pw3Vyu2B%2FbGMD1rQwHDBUZTAnKwP11MaOFQt%2BTV53krkIgvJgQT0Xl3UUxkngmW9785fUri75SSPoBk0z4DKyZnEBLxgTGRE8MzmXadQ%2BHDJ3rSI8IkkoomdnANpLsPN9oySshZ1h4BfOBvAmK0hQ4Gge1glH7qhxFjVWfX3tovZoL8e2smhuCRXxDsZtJh0ihbIeZUEnX8lGic%2B9IT6y4OskS2ZlrZNjvM10hcEesoPdHsT4oCvfhCNbUcJcueRKfsWlDCd9m6qmf42WVOc7UI0nE0oEvysMutWY971GVRKTLwIXRnTLSNOr6fSvJE3Q%3D%3D
解决方案
推荐阅读
- python - 如何在 Python 中加快集合 dict 的交集
- c# - 将密码添加到正则表达式 C#
- linux - Arch Linux:makepkg 创建另一个用户时出错
- fortran - 如何将 SHAPE() 的输出放入两个变量中?
- python - pandas.read_excel 列作为具有 NA 值的 int64
- python - 为什么 K-Medoids 在使用相同的数据时会给出不同的聚类?
- javascript - 不能包含多个 webpack 项目:Uncaught SyntaxError: missing ) after argument list
- amazon-web-services - 如何使用 localstack 部署 SAM 堆栈?
- php - 在 wordpress 的开始或结束页面中出现自定义分页错误
- javascript - 接口和类型之间有什么区别吗?