反应 - 将化身上传到firebase
下午好,我不知道如何将照片(Avatar)上传到Firebase,但是每个用户的头像都不同并在每个用户登录处保存。通过Firebase身份验证的用户注册
const [user, loading] = useAuthState(auth);
const [image , setImage] = useState("");
const storage = getStorage();
//upload function
const upload = ()=>{
const storageRef = ref(storage, `usersAvatar/${image.name}`);
if(image == null) return;
uploadBytes(storageRef, image).then(() =>{
getDownloadURL(storageRef).then((url) => {
setUrl(url);
})
})
}
// return
<input type="file" onChange={(e)=>{setImage(e.target.files[0])}}/>
<button onClick={upload}>Upload</button>
Good afternoon, I can’t figure out how to upload a photo (avatar) to firebase, but so that the avatar for each user is different and saved at each user login. User registration via firebase Authentication
const [user, loading] = useAuthState(auth);
const [image , setImage] = useState("");
const storage = getStorage();
//upload function
const upload = ()=>{
const storageRef = ref(storage, `usersAvatar/${image.name}`);
if(image == null) return;
uploadBytes(storageRef, image).then(() =>{
getDownloadURL(storageRef).then((url) => {
setUrl(url);
})
})
}
// return
<input type="file" onChange={(e)=>{setImage(e.target.files[0])}}/>
<button onClick={upload}>Upload</button>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您在云存储中使用此位置来存储用户的图像:
任何上传相同
image.name
的用户最终都会覆盖其他任何人的图像。相反,您要做的是基于用户UID上的上传位置。因此,例如:
Since you use this location in Cloud Storage to store the user's image:
Any user who uploads the same
image.name
will end up overwriting anyone else's image.What you'll want to do instead is based the upload location on the UID of the user. So for example: