簡體   English   中英

如何從Android搜索Amazon S3存儲桶

[英]How to search Amazon S3 Bucket from Android

我想從Android設備搜索特定的鍵或標簽。 例如,我要搜索圖像,如何使用Java代碼進行搜索?

謝謝

我不建議在移動設備上保留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;
}

同樣,您也可以獲取文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM