日志中返回对象在 Firebase 存储中未找到,但在 Firebase 存储控制台中存在。

huangapple go评论72阅读模式
英文:

Logs return object not found in firebase storage but it exist in the firebase storage console?

问题

我收到了以下错误:

FirebaseError: Firebase Storage:对象 'Bakery/Bakery Cuisine' 不存在(storage/object-not-found)


但是我最后检查的时候:

[![输入图片说明][1]][1]

路径是存在的,而且我大约30分钟前刚上传了一个文件。那么为什么 Firebase 存储说它不存在呢?

我想要做的是:能够下载 ```paramKey``` 路径下所有 .txt 文件中的内容,然后将该内容显示给用户看。

代码:

const [toReadfb, setToReadDatafb] = useState([])
useEffect (() => {
const rfb = sRef(storage, paramKey)
const output = getDownloadURL(rfb)
.then(function (url) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function(event) {
var blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
});
setToReadDatafb(output)
}, [])
console.log(toReadfb)


来自 ```toReadfb``` 的日志:

{"_1": 0, "_2": 0, "_3": null, "_4": null}


  [1]: https://i.stack.imgur.com/v6uWF.png
英文:

I got the following error:

FirebaseError: Firebase Storage: Object 'Bakery/Bakery Cuisine' does not exist. (storage/object-not-found)

But last I checked:

日志中返回对象在 Firebase 存储中未找到,但在 Firebase 存储控制台中存在。

The path is there and I just uploaded a file in like 30 mins ago. So how come firebase storage is saying it does not exist?

What I want to do: To be able to download the content insid all the .txt files under the path of paramKey and then display out that content for users to see.

Code:

const [toReadfb, setToReadDatafb] = useState([])
useEffect (() => {
    const rfb = sRef(storage, paramKey)
    const output = getDownloadURL(rfb)
    .then(function (url) {
      var xhr = new XMLHttpRequest();
      xhr.responseType = 'blob';
      xhr.onload = function(event) {
        var blob = xhr.response;
      };
      xhr.open('GET', url);
      xhr.send();
    });
    setToReadDatafb(output)
  }, [])
  console.log(toReadfb)

My logs from toReadfb

{"_1": 0, "_2": 0, "_3": null, "_4": null}

答案1

得分: 1

Bakery/Bakery Cuisine在你的截图中是一个文件夹,不是一个文件。无法获取文件夹的下载URL。

Post60e...5ea在你的截图中是一个文件。如果你想获取该文件,你需要传递它的完整路径(如:Bakery/Bakery Cuisine/Post60e...5ea)。

如果你想获取文件夹中文件的列表,请查阅Firebase文档上关于列出文件的部分。

英文:

The Bakery/Bakery Cuisine in your screenshot is a folder, not a file. There is no way to retrieve the download URL of a folder.

The Post60e...5ea in your screenshot is a file. If you want to retrieve that file, you'll need to pass its entire path (so: Bakery/Bakery Cuisine/Post60e...5ea).

If you want to get a list of the files in a folder, have a look at the Firebae documentation on listing files.

huangapple
  • 本文由 发表于 2023年3月9日 19:12:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定