【问题标题】:how to upload multiple images to firebase storage and store all urls in an array to firestore如何将多个图像上传到firebase存储并将所有url存储在一个数组中到firestore
【发布时间】:2021-07-23 07:59:07
【问题描述】:

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

期待答案谢谢

【问题讨论】:

  • 请将您的代码粘贴为文本。

标签: firebase google-cloud-firestore storage


【解决方案1】:

在您的 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()”。

【讨论】:

  • 我上电脑后会尽快修复格式:')
猜你喜欢
  • 2019-07-24
  • 2021-03-14
  • 2020-07-27
  • 2021-10-14
  • 2019-03-24
  • 1970-01-01
  • 2022-11-19
  • 2020-04-26
  • 2016-11-08
相关资源
最近更新 更多