如何从 Firebase 存储中下载 url 图像?

How to get download url for a Image from Firebase Storage?

我试图将图像上传到 firebase 存储,然后我试图下载 url 图像,但它不起作用。下面是代码:

const response = await fetch(selectedImage.uri);
const file = await response.blob();

const storageRef = ref(storage, `profile/${currentUser.email}`);
uploadBytes(storageRef, file).then( (snapshot) => {
  console.log('uploaded');
  getDownloadURL(storage).then( url => console.log(url)); // tried this outside of then block as well
});

文件已上传并可通过控制台访问,但 getDownloadURL 抛出错误:

[Unhandled promise rejection: TypeError: ref._throwIfRoot is not a function. (In 'ref._throwIfRoot('getDownloadURL')', 'ref._throwIfRoot' is undefined)]

不是将 storage 传递给 getDownloadURL(),而是传递 snapshot.ref

const response = await fetch(selectedImage.uri);
const file = await response.blob();

const storageRef = ref(storage, `profile/${currentUser.email}`);
uploadBytes(storageRef, file).then( (snapshot) => {
  console.log('uploaded');
  getDownloadURL(snapshot.ref).then( url => console.log(url));
});