【发布时间】:2022-07-13 03:29:04
【问题描述】:
我已使用 firebase 电子邮件和密码身份验证来注册用户,并将用户的 photoURL 设置为用户上传的图像。当我将图像的 src 设置为 user.photoURL 时,图像不会显示 - 但是当我检查代码时,我可以看到 src photoURL 是正确的。有谁知道为什么不显示?
这是图片的代码
<img className="profile-div__img" src={user.photoURL} alt="Profile picture"/>
这是我检查代码时显示的内容(但显示损坏的 img)
<img class="profile-div__img" src="https://firebasestorage.googleapis.com/v0/b/hobbi-react-app.appspot.com/o/thumbnails%2FKArVySiyqUfdp9YEfSpecVAnwHz2%2FIMG_3DB77D57E811-1.jpeg?alt=media&token=10948c92-b051-4e32-b852-a413c917a61c" alt="Profile picture">
这就是我设置 photoURL 的方式
// updateProfile(res.user, {displayName});
const uploadPath = `thumbnails/${res.user.uid}/${thumbnail.name}`;
const img = await uploadBytes(ref(storage, uploadPath, thumbnail));
const imgUrl = await getDownloadURL(img.ref);
// add display AND PHOTO_URL name to user
await updateProfile(res.user, { displayName, photoURL: imgUrl });
【问题讨论】:
标签: javascript firebase-authentication firebase-storage