-1

I am getting this error after upgrading the AWSSDK.S3(3.7.107) for dot net core version 6.0. The same code is working fine using AWSSDK.S3(3.5.0.4) for dot net core 3.1.

            var request = new GetPreSignedUrlRequest
            {
                BucketName = "bucket-name-mobile/test",
                Key = "637431660687617131_Sachin_Pakale.jpg",
                Expires = DateTime.Now.AddDays(1)
            };

            url = s3Client.GetPreSignedURL(request);

Found that the later version is encoding my URL by replaceing forward slash with %2F making it invalid.

<StringToSign>GET 1688208529 /bucket-name-mobile%2Ftest/637431660687617131_Sachin_Pakale.jpg</StringToSign>

My bucket name has forward slashes being the nested folder structure. Is there any workaround or provision to avoid this encoding? I am using USEast1 region.

Sachin Pakale
  • 292
  • 2
  • 4
  • 19
  • 1
    Did you try placing the subfolder in the key property ? (BucketName = "bucket-name-mobile", Key = "test/637431660687617131_Sachin_Pakale.jpg") (cf : https://lightrun.com/answers/aws-aws-sdk-java-v2-s3-bucket-name-containing-slash-character-fails-with-any-operation) – kipy Jul 03 '23 at 09:05
  • @kipy that worked. Thank you :) – Sachin Pakale Jul 03 '23 at 10:50

1 Answers1

1

Bucket name can't contain slashes. If your bucket contains "the folder" called test, then you need to modify your key parameter:

var request = new GetPreSignedUrlRequest
{
    BucketName = "bucket-name-mobile",
    Key = "test/637431660687617131_Sachin_Pakale.jpg",
    Expires = DateTime.Now.AddDays(1)
};

url = s3Client.GetPreSignedURL(request);
michail_w
  • 4,318
  • 4
  • 26
  • 43