【发布时间】:2017-11-27 06:14:24
【问题描述】:
我们正在使用预签名的 s3 url 来提供对存储在 s3 中的图像的 Web 访问。
我们用来生成预签名 url 的 java 代码类似于下面
String accessKey = ...;
String secretKey = ...;
String region = ...;
com.amazonaws.HttpMethod awsHttpMethod = ...;
String bucketName = ...;
String objectKey = ...;
Date expirationDate = ...;
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).withRegion(region).build();
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey);
generatePresignedUrlRequest.setMethod(awsHttpMethod);
generatePresignedUrlRequest.setExpiration(expirationDate);
URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
代码生成的url类似
但是,由于我们的存储桶命名标准包含点,因此调用上述 URL 会导致 SSL: no alternative certificate subject name matches target host name 'com.mycompany.personalpictures.s3.amazonaws.com' 错误
我在this post 中读到,根本原因是存储桶名称中的点,使用https://s3.amazonaws.com/com.mycompany.personalpictures/picture123.png 应该可以规避问题。
如何使用 url 格式 https://s3.amazonaws.com/mybucket/myfile 生成预签名的 url?
【问题讨论】:
标签: java ssl amazon-s3 pre-signed-url