Javascript 尝试使用getDownloadUrl时,列出使用firebase storage提供的404的所有文件
我正在尝试列出web应用程序文件夹下的文件,如下所示:Javascript 尝试使用getDownloadUrl时,列出使用firebase storage提供的404的所有文件,javascript,firebase,firebase-storage,Javascript,Firebase,Firebase Storage,我正在尝试列出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);
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);
});
});
});
const storageRef = firebase.app().storage('gs://some-name').ref();
const listRef = storageRef.child(`${Id1}`);
我成功地列出了res.items,但是当我尝试使用getDownloadURL()时,我得到了一个404引用,我确实注意到我在该项目的引用中得到了文件夹/图像,当我使用firebase存储控制台浏览文件时,它会浏览编码为%2F的斜杠“/”
我的推荐信如下:
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);
});
});
});
const storageRef = firebase.app().storage('gs://some-name').ref();
const listRef = storageRef.child(`${Id1}`);
保存图像时,我使用以下引用:
const imageRef = storageRef.child(`${Id1}/${this.file.name}`);
编辑:
我得到了默认的bucket作为响应,但是我在存储引用中设置了正确的存储bucket端点,这不是默认值。我以某种方式解决了这个问题 由于方法listAll()返回默认的bucket名称,因此我用所需的名称替换了bucket名称(不带gs/)
imgRef.location.bucket = 'non-default-bucket-name';
imgRef.getDownloadURL().then(url => url); //<- worked
imgRef.location.bucket='非默认bucket名称';
getDownloadURL()。然后(url=>url)// 我不知怎么解决了它有点不对劲
由于方法listAll()返回默认的bucket名称,因此我用所需的名称替换了bucket名称(不带gs/)
imgRef.location.bucket = 'non-default-bucket-name';
imgRef.getDownloadURL().then(url => url); //<- worked
imgRef.location.bucket='非默认bucket名称';
getDownloadURL()。然后(url=>url)//