摇篮
implementation platform('software.amazon.awssdk:bom:2.17.119')
implementation 'software.amazon.awssdk:s3'
用于获取预签名 URL 的代码
public static URL getPresignedUrl(String bucketName, String keyName ) {
PresignedGetObjectRequest presignedGetObjectRequest = null;
try {
AwsCredentialsProvider credentialsProvider = StaticCredentialsProvider.create
(AwsBasicCredentials.create(Access Key, Secret Key));
S3Presigner preSigner = S3Presigner.builder()
.credentialsProvider(credentialsProvider)
.region(Region.US_WEST_2).build();
GetObjectRequest getObjectRequest =
GetObjectRequest.builder()
.bucket(bucketName)
.key(keyName)
.build();
GetObjectPresignRequest getObjectPresignRequest = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
getObjectPresignRequest = GetObjectPresignRequest.builder()
.signatureDuration(Duration.ofDays(1))
.getObjectRequest(getObjectRequest)
.build();
}
// Generate the presigned request
presignedGetObjectRequest =
preSigner.presignGetObject(getObjectPresignRequest);
} catch (Exception e) {
e.getStackTrace();
}
return presignedGetObjectRequest.url();
}
如果 Fire OS 版本大于或等于 7.xx,则应用程序运行良好 在 Fire OS 版本 5.xx 上崩溃
在线崩溃 S3Presigner preSigner = S3Presigner.builder()
需要帮忙