[英]Update photoURL Firebase v9 web, react Javascript
我正在按照 Udemy firebase Udemy 教程使用 javascript 創建 firebase web 應用程序並做出反應。 課程材料有點過時了。 我想知道如何更改用戶的 photoURL - 他們使用 email 和密碼注冊,我有一個單獨的掛鈎來處理注冊信息。
下面是 Udemy 課程提供的用於更新用戶照片 URL 的代碼——有誰知道我將如何在 Firebase v9 中編寫此代碼? 謝謝!
// upload user thumbnail
const uploadPath = `thumbnails/${res.user.uid}/${thumbnail.name}`
const img = await projectStorage.ref(uploadPath).put(thumbnail)
const imgUrl = await img.ref.getDownloadURL()
// add display AND PHOTO_URL name to user
await res.user.updateProfile({ displayName, photoURL: imgUrl })
從 v9 之前的版本重寫到 v9 通常非常簡單,特別是如果您遵循升級指南或比較上傳文件文檔中的 v8 和 v9 示例。
在您的代碼中,此 v8 代碼:
const uploadPath = `thumbnails/${res.user.uid}/${thumbnail.name}`
const img = await projectStorage.ref(uploadPath).put(thumbnail)
const imgUrl = await img.ref.getDownloadURL()
// add display AND PHOTO_URL name to user
await res.user.updateProfile({ displayName, photoURL: imgUrl })
在 v9 及更高版本中變成這樣:
const uploadPath = `thumbnails/${res.user.uid}/${thumbnail.name}`
const img = await uploadBytes(ref(projectStorage, uploadPath, thumbnail))
const imgUrl = await getDownloadUrl(img.ref)
// add display AND PHOTO_URL name to user
await updateProfile(res.user, { displayName, photoURL: imgUrl })
如果仔細觀察,您會發現大部分更改只是將命名空間object.operation()
方法調用移動到模塊化/功能operation(object)
形式。 除此之外,這里最大的區別是put
現在稱為uploadBytes
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.