如何将多个图像上传到 firebase 存储并将所有 url 存储在一个数组中到 firestore

时间:2021-07-23 07:59:07

标签: firebase google-cloud-firestore storage

这是我的代码,我可以获取所有链接,但我无法将它们存储在数组中并将它们发送到 Firebase here is the codes here are the codes

期待答案,谢谢

1 个答案:

答案 0 :(得分:0)

在您的 uploadImageAsPromise 函数中:

// make the function async 
const storageRef = firebase.storage().ref();
  const fileUploads = files.map(file => storageRef.child(file.name).put(file));

const uploadRequests = await Promise.all(fileUploads)
      
  const fileURLReqs = uploadRequests.map(f => f.ref.getDownloadURL())
  const fileUrls = await Promise.all(fileURLReqs)

fileUrls 将是下载 URL 的数组。

如果您需要显示每次上传的进度,那么您可以在 fileUploads 数组上运行一个循环,并在每个元素上使用“task.on()”。

相关问题