列出 Firebase 存储对象会忽略所有元数据

Listing Firebase Storage objects omits all metadata

我一直在尝试获取我的存储桶的特定文件夹中所有文件的列表,它工作得很好,但没有关于本文档中描述的对象元的信息:https://cloud.google.com/storage/docs/json_api/v1/objects#resource

项目对象的形状不同,而是为数组中的每个项目提供一个“ReferenceCompat”。

相反 - 唯一提供的属性是 bucket、fullPath 和 name。

有人知道这是为什么吗?

https://firebase.google.com/docs/storage/web/list-files

  const storageRef = firebase.storage().ref(folder);
  const listFiles = function listFilesAndSaveToSlice() {
    storageRef
      .listAll()
      .then((res) => {
        res.items.forEach((item) => {
           let {name, id, owner, acl, ...etc} = item;
           // {name: name, id: undefined, ...undefined}
        });
      })
      .catch((error) => {

      });
  };

这是提供的对象,而不是预期的对象:

ReferenceCompat: {
    "_delegate": {
        "_service": {
            "app": {
                "name": "[DEFAULT]",
                "automaticDataCollectionEnabled": false,
                "options": {
                    "apiKey": "xxxxxxx-xxxxxxxxx",
                    "authDomain": "xxxxxx",
                    "projectId": "xxxx",
                    "storageBucket": "xxxxxx",
                    "messagingSenderId": "xxxxxxxxx",
                    "appId": "xxxxxxxx"
                }
            },
            "_authProvider": {
                "name": "auth-internal",
                "container": {
                    "name": "[DEFAULT]",
                    "providers": {}
                },
                "component": {
                    "name": "auth-internal",
                    "multipleInstances": false,
                    "instantiationMode": "LAZY",
                    "type": "PRIVATE"
                },
                "instances": {},
                "instancesDeferred": {},
                "onInitCallbacks": {}
            },
            "_appCheckProvider": {
                "name": "app-check-internal",
                "container": {
                    "name": "[DEFAULT]",
                    "providers": {}
                },
                "component": null,
                "instances": {},
                "instancesDeferred": {},
                "onInitCallbacks": {}
            },
            "_pool": {},
            "_firebaseVersion": "8.6.5",
            "_bucket": {
                "bucket": "xxxxx",
                "path_": ""
            },
            "_host": "firebasestorage.googleapis.com",
            "_appId": null,
            "_deleted": false,
            "_maxOperationRetryTime": 120000,
            "_maxUploadRetryTime": 600000,
            "_requests": {}
        },
        "_location": {
            "bucket": "xxxxxxxxxx",
            "path_": "samples/coming to an end v2.mp3.asd"
        }
    },
    "storage": {
        "app": {
            "name": "[DEFAULT]",
            "automaticDataCollectionEnabled": false,
            "options": {
                "apiKey": "xxxxxx",
                "authDomain": "xxxxxx",
                "projectId": "xxxxx",
                "storageBucket": "xxxxx",
                "messagingSenderId": "xxxxx",
                "appId": "xxxx"
            }
        },
        "_delegate": {
            "app": {
                "name": "[DEFAULT]",
                "automaticDataCollectionEnabled": false,
                "options": {
                    "apiKey": "xxxxxxxxxxxxxx",
                    "authDomain": "xxxxxxx",
                    "projectId": "xxxxxx",
                    "storageBucket": "xxxxx",
                    "messagingSenderId": "xxxxx",
                    "appId": "xxxxxx"
                }
            },
            "_authProvider": {
                "name": "auth-internal",
                "container": {
                    "name": "[DEFAULT]",
                    "providers": {}
                },
                "component": {
                    "name": "auth-internal",
                    "multipleInstances": false,
                    "instantiationMode": "LAZY",
                    "type": "PRIVATE"
                },
                "instances": {},
                "instancesDeferred": {},
                "onInitCallbacks": {}
            },
            "_appCheckProvider": {
                "name": "app-check-internal",
                "container": {
                    "name": "[DEFAULT]",
                    "providers": {}
                },
                "component": null,
                "instances": {},
                "instancesDeferred": {},
                "onInitCallbacks": {}
            },
            "_pool": {},
            "_firebaseVersion": "8.6.5",
            "_bucket": {
                "bucket": "megatech-ltd.appspot.com",
                "path_": ""
            },
            "_host": "firebasestorage.googleapis.com",
            "_appId": null,
            "_deleted": false,
            "_maxOperationRetryTime": 120000,
            "_maxUploadRetryTime": 600000,
            "_requests": {}
        },
        "INTERNAL": {}
    }
}

如 firebase 存储 api 文档中所述,list() returns 一个 ListResult which in turn may contain multiple Reference 个对象。

如果您想获取 list() 返回的所有对象的元数据,您需要对每个返回的文件调用 Reference.getMetadata()