【问题标题】:List all files using firebase storage gives me 404 when trying to use getDownloadUrl尝试使用 getDownloadUrl 时,列出所有使用 firebase 存储的文件给我 404
【发布时间】:2020-08-06 04:09:51
【问题描述】:

我正在尝试在 Web 应用中的文件夹下列出文件,如下所示:

listRef.listAll().then((res) => {
    // I get the list of items here
    res.items.forEach((imgRef) => {
        // 404 error
        imgRef.getDownloadURL().then((url) => {
            console.log(url);
            mapFile(url, imgRef.metadata);
        });
     });
 });

我成功列出 res.items,但是当我尝试使用 getDownloadURL() 时,我得到了 404 引用,我注意到我得到了 folder/image 在项目的引用中,当我使用 firebase 存储控制台浏览文件时,它会浏览编码为 %2F 的斜杠“/”

我的参考如下:

 const storageRef = firebase.app().storage('gs://some-name').ref();
 const listRef = storageRef.child(`${Id1}`);

当我保存图像时,我使用以下参考:

const imageRef = storageRef.child(`${Id1}/${this.file.name}`);

编辑:

我得到了默认存储桶作为响应,但是我在存储引用中设置了正确的存储桶端点,这不是默认值。

【问题讨论】:

    标签: javascript firebase firebase-storage


    【解决方案1】:

    我以某种方式解决了这个问题

    由于方法 listAll() 返回默认存储桶名称,我将存储桶名称(不带 gs//)替换为我需要的 name

    imgRef.location.bucket = 'non-default-bucket-name';
    imgRef.getDownloadURL().then(url => url); //<- worked
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2021-04-06
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 2019-05-29
      相关资源
      最近更新 更多