我正在尝试读取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上
我有Dashboard-&gt; Identity&amp;访问管理 - &gt;创建IAM用户(使用AwsCredentials.properties文件中的密钥和访问密钥)。
添加了S3ReadOnlyAccess
政策和S3FullAccess
政策
在我的s3存储桶中,我为List
和View Properties
添加了Everyone
和Authenticated_users
。
在我的db文件中,我为Open/Download
和View Properties
添加了Everyone
和Authenticated Users
。
例外
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()
我在这里缺少什么?
修改
我尝试了这个link的代码,没有与上面相同的例外情况。
我还尝试将AwsCredentials.properties的位置移动到libs文件夹。在这里我得到了一个不同的例外,暗示AwsCredentials.properties文件的位置应该在项目的src文件夹中,而不是libs文件夹。
03-09 19:19:57.109:E / AndroidRuntime(14502):com.amazonaws.AmazonClientException:无法从类路径上的/AwsCredentials.properties文件加载AWS凭证
答案 0 :(得分:0)
你能解决这个问题吗?虽然在不同的情况下,我们正在遇到同样的问题。我们认为这与时间有关,但无法确定。