繁体   English   中英

如何上传相册到firebase存储?

[英]How to upload an album to firebase storage?

介绍

您好,直到今天我才将一张图片上传到带有进度条的存储中,效果很好。

现在,我需要上传多张图片的相册。 我认为这将是类似但迭代的东西......我正在做的是:

1. Create a blob for each image in the albun
2. Upload them one by one to the storage.

问题

问题是,如果我将它们一个接一个地上传,将创建多个 uploadTasks,而我只需要一个进度条。 有没有办法一次上传多张图片?

代码

const { images, description, location, tags } = postInfo; // images is an array of images' uris

// TODO - Build the blobs (for each image in images)

// TODO - Post UUID = Firt Blob UUID

// Create a storage referece
const storageRef = firebase.getStorage().ref("photos").child(postId);

// TODO - Upload all blobs to storage
// const uploadTask = storageRef.put(blob); <----------- Not only a blob, just all the album

uploadTask.on("state_changed", (taskSnapshot) => { // How to get a unique uploadTask for all blobs??
  // Update progress bar
  const percent =
    (taskSnapshot.bytesTransferred / taskSnapshot.totalBytes) * 100;

  setUploadProgress(percent);
});

似乎您需要同时运行多个异步函数。 试试这个流程

  1. 创建多个同时上传照片的异步函数(承诺)。
  2. 收听这些上传并每 0.1 秒/每次更改时总结 bytesTransferred 和 totalBytes。
  3. 将所述 bytesTransferred 除以 totalBytes,瞧,你的上传进度分数。

感谢你的提问。 这是一个有趣的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM