Closed Anuragh6911 closed 10 months ago
String bucketFullPath = generateFullBucketPath(appId, folder);
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketFullPath,
keyName);
The first argument of GeneratePresignedUrlRequest
must be just the bucket name. If you're providing any additional prefixes as part of the bucket name, they need to be part of the object name instead.
Don't use: GeneratePresignedUrlRequest("bucket/prefix", "key")
Instead, use: GeneratePresignedUrlRequest("bucket", "prefix/key")
Thank you @debora-ito this fixed my issue.
I was wondering why this worked with the micronaut version 3.7.9 ? I used the same version aws-sdk in both cases.
We are not the maintainers of Micronaut, you need to reach out to them. Closing this.
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
SignatureDoesNotMatch issues while uploading image with pre-signedurl
public UploadObject getPreSignedUploadUrl(String appId, String folder) { try { // Generate the pre-signed URL. String keyName = String.valueOf(UUID.randomUUID()); Date expiration = generateOneDayExpirationTime(); String bucketFullPath = generateFullBucketPath(appId, folder); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketFullPath, keyName); generatePresignedUrlRequest.withExpiration(expiration) .withMethod(HttpMethod.PUT); URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest); log.debug("PreSigned upload url : {} ", url); return new UploadObject(keyName, url.toString()); } catch (SdkClientException e) { log.error("Exception while generating pre-signed upload url", e); return null; } }
This is the code I used for generating the pre-signed url. I am currently using the micronaut version 4.2.1. While trying to post an image using the pre-signed url generated I get an error SignatureDoesNotMatch. This is the pre-signed url I used to post an image which was generated from the above code:
https://s3.us-east-2.amazonaws.com/healthusbucket%2Fhealth%2Fprescriptions-nepals/bfcdab42-74ff-4548-82ae-fcc795c71947?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240125T103508Z&X-Amz-SignedHeaders=host&X-Amz-Expires=35999&X-Amz-Credential=AKIAUW6YCO3PMEL2R5ZM%2F20240125%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Signature=19ffb016336162977910159d021f02ae250983a30a22ed732af423544b00976b
I also tired to run the same code in Micronaut version 3.7.9 , and I posted an Image with the pre-signed url. I didn't get any issue this time. This was the pre-signed url generated:
https://s3.us-east-2.amazonaws.com/healthusbucket/health/prescriptions-nepals/c606370a-c8e5-4312-b668-832434880df7?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240125T104212Z&X-Amz-SignedHeaders=host&X-Amz-Expires=35999&X-Amz-Credential=AKIAUW6YCO3PMEL2R5ZM%2F20240125%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Signature=43aa27e4f5ed330f3c2356114ac9721e6ec280f9acea5917862be576a314cf0b
You need to use this pre-signed URL with PUT request
What could be the issue here ?
Expected Behavior
https://s3.us-east-2.amazonaws.com/healthusbucket%2Fhealth%2Fprescriptions-nepals/bfcdab42-74ff-4548-82ae-fcc795c71947?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240125T103508Z&X-Amz-SignedHeaders=host&X-Amz-Expires=35999&X-Amz-Credential=AKIAUW6YCO3PMEL2R5ZM%2F20240125%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Signature=19ffb016336162977910159d021f02ae250983a30a22ed732af423544b00976b
While posting the image using the pre-signed given above url the image should be uploaded in the AWS s3 bucket.
Current Behavior
I am getting an error called SignatureDoesNotMatch. The more detail to this error is given below:
`<?xml version="1.0" encoding="UTF-8"?>
SignatureDoesNotMatch