我正在尝试将文件/图像/视频从android上传到AWS s3存储桶。一些视频已成功上传,但有时当我上传视频时却未上传并引发以下错误:
com.amazonaws.AmazonClientException: Unable to verify integrity of data upload. Client
calculated content hash didn't match hash calculated by Amazon S3. You may need to delete
the data stored in Amazon S3.
2020-01-16 16:58:15.065 30740-30740/com.sirona.android W/System.err: at
com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1985)
2020-01-16 16:58:15.065 30740-30740/com.sirona.android W/System.err: at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:277)
2020-01-16 16:58:15.065 30740-30740/com.sirona.android W/System.err: at
com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:115)
2020-01-16 16:58:15.065 30740-30740/com.sirona.android W/System.err: at
com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:60)
2020-01-16 16:58:15.065 30740-30740/com.sirona.android W/System.err: at
java.util.concurrent.FutureTask.run(FutureTask.java:266)
2020-01-16 16:58:15.066 30740-30740/com.sirona.android W/System.err: at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-01-16 16:58:15.066 30740-30740/com.sirona.android W/System.err: at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2020-01-16 16:58:15.066 30740-30740/com.sirona.android W/System.err: at
java.lang.Thread.run(Thread.java:764)
这是我的代码
private fun getS3Client(
accessKey: String,
secretKey: String,
sessionToken: String
): AmazonS3Client? {
var sS3Client: AmazonS3Client? = null
try {
val region: Region = Region.getRegion("us-west-2")
val credentials =
BasicSessionCredentials(accessKey, secretKey, sessionToken)
val clientConfiguration = ClientConfiguration()
.withMaxErrorRetry(3) // 3 retries
.withConnectionTimeout(120000) // 120,000 ms
.withSocketTimeout(120000) // 120,000 ms
sS3Client = AmazonS3Client(credentials, region, clientConfiguration)
} catch (e: JSONException) {
e.printStackTrace()
}
return sS3Client
}
val observer: TransferObserver =
transferUtility.upload(bucket_name, file.name, file,objectMetadata)
提前谢谢!