首页 > 解决方案 > 尝试列出 Firebase 存储桶中的文件时出现 NSInternalInconsistencyException

问题描述

我正在尝试使用以下代码获取我的 firebase 存储桶中所有对象的列表:

[listingReference listWithMaxResults:1000 completion:^(FIRStorageListResult * _Nonnull result, NSError * _Nullable error) {
        if(error != nil){
            NSLog(@"Error listing files");
            NSLog(@"%@", error);
        } else {
            NSArray<FIRStorageReference *> *entries = result.prefixes;
            NSArray<FIRStorageReference *> *entryItems = result.items;
            NSLog(@"List folder complete");
            NSLog(@"%@", entries);
            NSLog(@"%@", entryItems);
        }
    }];

但是,当我运行代码时,出现以下错误:

由于未捕获的异常而终止应用程序:

NSInternalInconsistencyException',原因:'预期 gs://bucketname1/ 是 gs://bucketname1/testfile 的子元素

listingReference通过打印文件路径检查了我的文件路径,它输出gs://bucketname1/了我认为正确的内容,因为我想列出存储桶中的所有文件。有什么我做错了吗?

标签: objective-cfirebasefirebase-storage

解决方案


在我看来,您实际上无法查询存储桶中的所有文件,因此我在存储桶内创建了一个文件夹并将我的文件保存在该文件夹中,并且可以在那里查询它们。


推荐阅读