The*_*3.0 5 javascript google-cloud-storage firebase firebase-authentication google-cloud-functions
我正在将图像上传到 Firebase 存储,并希望将其图像保存为 Firebase 身份验证中的 photoURL。但是,当我在使用 getsigned URL 后上传图像 URL 时,我收到错误
错误:photoURL 字段必须是有效的 URL。
我知道该 URL 是有效的,因为我已经从控制台输出中检查了它。我尝试过使用decodeURI,甚至研究了firebase-admin-node
跟踪的源代码,一直到一个名为 auth-api-requests.ts的文件,该文件在第252行检查名为this的函数中的URL,validator.isURL(request.photoUrl)
这让我发现定义函数的文件validator.ts定义了该.isURL()
函数的第 152 行,检查是针对禁止字符的字符串执行的。我不想篡改 Firebase 源代码,但我找不到任何解决方案。应该有一种更简单的解决方案,可以将一个 google 函数的返回.getSignedURL()
值用作另一个.updateUser({photoURL:
}) 的参数,特别是考虑到无法再firebase.getDownloadURL()
从 google 云函数节点调用。感谢您为解决此问题提供的任何帮助。
var downloadURL = "";
await admin.storage().bucket("gs://****firebase.appspot.com").file(storageRef).getSignedUrl({"action":"read","expires":Date.now() + 500*365*24*3600000}).then((value) => {
console.log("value after requesting signed URL: " + JSON.stringify(value));
downloadURL = value;
return value;
}).catch((error) => {
console.log("error perfoming signed URL: " + error);
return error;
})
const url = decodeURI(downloadURL)
console.log("\nThe decodeURI url: " + url + "\n");
await admin.auth().updateUser(userID,{photoURL:url}).then((user) => {
console.log("User update ran a success: " + JSON.stringify(user));
return true;
}).catch((error) => {
console.log("An error occured in getting the user: " + error);
return error;
});
Run Code Online (Sandbox Code Playgroud)
对用户 photoURL(仅为联合登录用户填充)进行硬编码并不是一个好主意,因为它可能会发生变化。换句话说,Twitter 用户可能会更改他们的个人资料照片。 firebase.auth()
在用户登录时为您提供最新的用户元数据。
它只会增加保存此类元数据的维护开销 - 无需为此烦恼。
归档时间: |
|
查看次数: |
2028 次 |
最近记录: |