Reputation: 1
My example:
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setProtocol(Protocol.HTTP);
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 s3client = new AmazonS3Client(credentials, clientConfig);
Region region = Region.getRegion(Regions.EU_WEST_1);
s3client.setRegion(region);
s3client.setEndpoint(serverCeph);
Bucket bucket = s3client.createBucket(bucketName);
File file = new File(fileNameTest);
AccessControlList acl = new AccessControlList();
acl.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
s3client.putObject(new PutObjectRequest(bucketName, keyObject, file).withAccessControlList(acl));
s3client.setObjectAcl(bucket.getName(), keyObject,CannedAccessControlList.Private);
// Generate URL
System.out.println("Generating pre-signed URL.");
java.util.Date expiration = new java.util.Date();
long milliSeconds = expiration.getTime();
milliSeconds += 1000 * 60 * 60; // Add 1 hour.
expiration.setTime(milliSeconds);
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, keyObject);
generatePresignedUrlRequest.setMethod(HttpMethod.GET);
generatePresignedUrlRequest.setExpiration(expiration);
generatePresignedUrlRequest.setContentType("image/png");
URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest);
System.out.println("Pre-Signed URL = " + url.toString());
If I using s3client.setObjectAcl(bucket.getName(), keyObject,CannedAccessControlList.PublicRead);
then i can get URL and this work fine
But If I used s3client.setObjectAcl(bucket.getName(), keyObject,CannedAccessControlList.Private);
then I can get URL and The URL not working
I always recived error below when I passed the URl into browsers.
<Error>
<Code>SignatureDoesNotMatch</Code>
<RequestId>tx000000000000000068415-0058d62341-5229e3-default</RequestId>
<HostId>5229e3-default-default</HostId>
</Error>
And this is URL I generated:
Somebody can have any idea or the way that I used to run URL correctly?
Upvotes: 0
Views: 2274
Reputation: 2126
Just in case if somebody is looking for the solution.
If you see SignatureDoesNotMatch
- first thing to check is the "Content-Type" header that you are sending when uploading a file. It must have the same value that you used for the URL generation.
Upvotes: 0