简体   繁体   English

上传多张图片到Firebase存储得到url张

[英]Get url of multi images when upload them to Firebase Storage

can you help me with getting array of URLs while uploading images to firebase?你能帮我在将图像上传到 firebase 时获取 URL 数组吗?

my imageUrl = [undefined, undefined] when uploading 2 img上传 2 img 时我的 imageUrl = [undefined, undefined]

export const handleUploadProductPhoto = async (files) => {
  const imageUrl = await Promise.all(
    files.map((file) => {
      new Promise((resolve, reject) => {
        const uploadTask = firebase
          .storage()
          .ref()
          .child(`your/file/path/${file.name}`)
          .put(file);
        uploadTask.on(
          firebase.storage.TaskEvent.STATE_CHANGED,
          (snapshot) => {
            const progress =
              (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
            if (snapshot.state === firebase.storage.TaskState.RUNNING) {
              console.log(`Progress: ${progress}%`);
            }
          },
          (error) => console.log(error),
          () => {
            uploadTask.snapshot.ref
              .getDownloadURL()
              .then((url) => resolve(url));  //I have success here - two urls
          }
        );
      });
    })
  ).then((res) => console.log(res));
};

You're missing a return on your new Promise .您缺少new Promisereturn So it should be:所以应该是:

return new Promise((resolve, reject) => {
  ...

Without that return , each files.map((file) => { returns nothing (so undefined ) and that is what Promise.all then passes into your then .如果没有那个return ,每个files.map((file) => {什么都不返回(所以undefined ),这就是Promise.all然后传递给你的then

暂无
暂无

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

相关问题 尝试将图像上传到 Firebase 存储时出错 - Error when trying to upload images to Firebase storage 如何在firebase存储中上传一张图片,在firebase文档字段中获取url - How to upload a picture in firebase storage and get it url in firebase document field 我正在尝试将图像上传到 firebase 存储并获取下载 url - I'm trying to upload an image to firebase storage and get the download url 将文件上传到 firebase 存储并获取 URL 以保存在反应中的数据库中 - Upload File to firebase storage and get URL to save in a database in react 如何上传SVG张图片到firebase存储? - How to upload SVG images on firebase storage? 在 firebase 存储上获取 URL 图像 - Get URL of image on firebase storage 将 Blob Url 上传到 Firebase 存储 | Flutter - Upload Blob Url to Firebase Storage | Flutter 从图库中选择多张图片,然后将它们上传到 Firebase Storgae - 但出现 ENOENT(没有此类文件或目录)错误 - Select multiple images from gallery and then upload them to Firebase Storgae - but get an ENOENT (No such file or directory) error 如何获取 URL 中存储在 Firebase 中的图像存储在特定文件夹中 | 安卓 | Java - How to get URL of Images from that are stored in Firebase Storage in specific folder | Androi | Java 如何从 firebase 存储中获取图像 URL 列表并将其上传到云 firestore? - How to get a list of image URL from firebase storage and upload it to cloud firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM