【发布时间】:2019-06-05 21:39:23
【问题描述】:
我正在将图片上传到 Firebase 存储,并希望将其图片保存为 Firebase 身份验证中的 photoURL。但是,当我在使用获取签名 URL 后去上传图像 URL 时,我收到错误
错误:photoURL 字段必须是有效的 URL。
我知道该 URL 是有效的,因为我已经从控制台输出了它。我曾尝试使用decodeURI,甚至查看firebase-admin-node 的源代码一直跟踪到一个名为auth-api-requests.ts 的文件,该文件在第252 行检查名为validator.isURL(request.photoUrl) 的函数中的URL这使我进入了定义函数validator.ts 的文件,该文件在此函数的第 152 行定义了.isURL(),检查是针对一串禁止字符执行的。我不想篡改 Firebase 源代码,但我找不到任何解决方案。应该有一个更简单的解决方案,用于从一个谷歌函数 .getSignedURL() 返回用作另一个 .updateUser({photoURL:} 中的参数),特别是考虑到不能再从谷歌云函数节点调用 firebase.getDownloadURL()。感谢您为解决此问题提供的任何帮助。
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;
});
【问题讨论】:
标签: javascript firebase firebase-authentication google-cloud-storage google-cloud-functions