【问题标题】:Google Cloud doesn't recognize subfolder as having more files?Google Cloud 不将子文件夹识别为有更多文件?
【发布时间】:2020-10-29 18:15:01
【问题描述】:

最近一直在尝试通过以下方式验证 GCS 存储桶中确实存在哪些路径。

return StorageOptions.getDefaultInstance().getService()
      .list("my-bucket-name", Storage.BlobListOption.prefix(("folder-inside/yet-another-folder/")))
      .hasNextPage();

考虑桶内的以下结构。

- my-bucket-name
|-- folder-inside
   |-- yet-another-folder
      | -- file.txt

只要yet-another-folder 存在,它就不会是空的。两种情况都应返回 true,yet-another-folder 现有或 yet-another-folder 包含更多文件。

但是,由于某种原因,每次都返回 false

【问题讨论】:

    标签: java google-cloud-platform google-cloud-storage


    【解决方案1】:

    列表返回一个可分页的结果(默认值:每页 1000 个没有 ACL 详细信息,否则为 200)。如果有更多结果,则 hasNextPage() 为真,否则为假。

    在您的情况下,您只有 1 个文件,它在您的列表调用中返回,并且没有下一页结果,因此 hasNextPage() 为 false。

    最好测试返回列表的大小。如果为 0,则不存在文件且不存在目录。如果为1,则只有目录存在,没有文件。

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多