Android应用无法下载S3 Forbidden(服务:Amazon S3;状态代码:403;错误代码:null)

时间:2015-03-09 08:13:34

标签: android amazon-s3

我正在尝试读取s3存储桶的元数据(版本),然后决定是否需要下载sqlite.db文件。

代码

private void downloadLatestSEZDBFile() {
        Object result;
        String finalDatabasePath = getFinalDatabasePath();
        s3client = new AmazonS3Client(
                new ClasspathPropertiesFileCredentialsProvider());
        try {
-->Exception here--> newVersion = Integer.valueOf((String) s3client.getObjectMetadata(
                    bucketName, sezDB).getRawMetadataValue(versionMetadata));
        } catch (NumberFormatException e) {

        }
        Log.d("myapp", "SEZDB version returned " + newVersion);
        File finalDatabase = new File(finalDatabasePath);
        if (newVersion == 1 || !finalDatabase.exists()) {
            copyVersion1FromAssets(finalDatabase);
            result = finalDatabase.getAbsolutePath();
        } else if (newVersion != God.getSEZDBVersion(context)) {
            GetObjectRequest objectRequest = new GetObjectRequest(bucketName,
                    sezDB);
            s3client.getObject(objectRequest, finalDatabase);
            result = finalDatabase.getAbsolutePath();
        } else
            result = null;

        if (result != null) {
            God.setSEZDBVersion(context, newVersion);
            sqliteDatabase = SQLiteDatabase.openOrCreateDatabase(
                    finalDatabasePath, null);
            God.initializeCityVariables(context);
        }
    }

我已将AwsCredentials.properties复制到我的src文件夹

secretKey=<mysecretkey>
accessKey=<myaccesskey>

在AWS上

  1. 我有Dashboard-&gt; Identity&amp;访问管理 - &gt;创建IAM用户(使用AwsCredentials.properties文件中的密钥和访问密钥)。

  2. 添加了S3ReadOnlyAccess政策和S3FullAccess政策

  3. 在我的s3存储桶中,我为ListView Properties添加了EveryoneAuthenticated_users

  4. 在我的db文件中,我为Open/DownloadView Properties添加了EveryoneAuthenticated Users

  5. 例外

    com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: null; Request ID: DE30A17F3E9E3B1C), S3 Extended Request ID: fdl02MUW0qzC6WPzO52nUBCw4+LYxAPlUuPOWN2lJd+LRJLC/nUoM2AJip5yWxeG2fGhy7HIbLQ=
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(Unknown Source)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.amazonaws.http.AmazonHttpClient.executeHelper(Unknown Source)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.amazonaws.http.AmazonHttpClient.execute(Unknown Source)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.amazonaws.services.s3.AmazonS3Client.invoke(Unknown Source)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(Unknown Source)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(Unknown Source)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.myapp.support.ActiveSEZDB.downloadLatestSEZDBFile(ActiveSEZDB.java:262)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.myapp.support.ActiveSEZDB.access$0(ActiveSEZDB.java:256)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at com.myapp.support.ActiveSEZDB$1.run(ActiveSEZDB.java:43)
    03-09 09:26:34.195: E/AndroidRuntime(31116):    at java.lang.Thread.run(Thread.java:1019)
    03-09 09:26:34.203: E/(1490): Dumpstate > /data/log/dumpstate_app_error
    03-09 09:26:39.625: E/Launcher(1588): setWindowOpaque()
    

    我在这里缺少什么?

    修改

    1. 我尝试了这个link的代码,没有与上面相同的例外情况。

    2. 我还尝试将AwsCredentials.properties的位置移动到libs文件夹。在这里我得到了一个不同的例外,暗示AwsCredentials.properties文件的位置应该在项目的src文件夹中,而不是libs文件夹。

    3.   

      03-09 19:19:57.109:E / AndroidRuntime(14502):com.amazonaws.AmazonClientException:无法从类路径上的/AwsCredentials.properties文件加载AWS凭证

      1. 我使用IAM用户登录AWS,并且能够查看对象的元数据。

1 个答案:

答案 0 :(得分:0)

你能解决这个问题吗?虽然在不同的情况下,我们正在遇到同样的问题。我们认为这与时间有关,但无法确定。