【问题标题】:Amplify.Storage: Is there a way to list only the files in my bucket?Amplify.Storage:有没有办法只列出我存储桶中的文件?
【发布时间】:2021-12-21 23:59:42
【问题描述】:

我正在尝试通过以下方式列出存储桶中的所有文件:

Amplify.Storage.list("",
    result -> {
        for (StorageItem item : result.getItems()) {
            Log.i("MyAmplifyApp", "File: " + item.getKey() + ", Hash: " + item.getETag());
        }
    },
    error -> Log.e("MyAmplifyApp", "List failure", error)
);

但我只对文件感兴趣,而不是目录。我该怎么做?

【问题讨论】:

    标签: android amazon-s3 aws-amplify


    【解决方案1】:

    我无法为我的问题找到明确的解决方案。这是我写的最接近的解决方案:

    Amplify.Storage.list("",
        result -> {
            for (StorageItem item : result.getItems()) {
                if(item.getSize() == 0) {
                    Log.i(TAG, "File is empty, skip: " + item.getKey());
                    continue;
                }
                Log.i("MyAmplifyApp", "File: " + item.getKey() + ", Hash: " + item.getETag());
            }
        }
        error -> Log.e("MyAmplifyApp", "List failure", error)
    );
    

    这只是忽略任何大小为零字节的StorageItem。这适用于我的情况,因为除了目录之外,我对空文件也不感兴趣。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 2021-10-28
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-25
      相关资源
      最近更新 更多