【问题标题】:How to search Amazon S3 Bucket from Android如何从 Android 搜索 Amazon S3 存储桶
【发布时间】:2018-06-07 20:25:16
【问题描述】:

我想从 android 设备中搜索特定的键或标签。例如我想搜索一个图像,我该如何使用 java 代码呢?

谢谢

【问题讨论】:

    标签: java android amazon-web-services android-studio amazon-s3


    【解决方案1】:

    我不建议将 AWS 凭证保存在移动设备上。您可以将存储桶公开(如果它是安全的),或者创建一个后端服务进行搜索。 对于公共存储桶,您将获得确定性 url,因此您可以直接使用图像名称调用 url,它会返回图像或会给您一个错误。 如果您创建后端服务(或在 Android 设备中使用),请首先创建 S3 客户端。

    public boolean fileExists(String fileName, String s3Bucket) {
        boolean fileExists = true;
        try {
            s3client.getObjectMetadata(s3Bucket, fileName);
        } catch (final AmazonS3Exception s3e) {
            if (s3e.getStatusCode() == 404) {
                // i.e. 404: NoSuchKey - The specified key does not exist
                fileExists = false;
            } else {
                throw s3e; // rethrow all S3 exceptions other than 404
            }
        }
    
        return fileExists;
    }
    

    同样,您也可以获取文件。

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 2016-08-25
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 2011-09-10
      相关资源
      最近更新 更多