Aws-sdk-net: Non US-ASCII characters in metadata throws AmazonS3Exception

Created on 23 Apr 2020  路  4Comments  路  Source: aws/aws-sdk-net

Expected Behavior


Following the information here, one would think that adding a non US-ASCII metadata value would be automatically handled

https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html

So storing any unicode should work

Current Behavior





Trying to store a non US-ASCII value fails with SignatureDoesNotMatch and the error message:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

Steps to Reproduce (for bugs)




The following code gives the error:

var s3c = new AmazonS3Client();

var por = new PutObjectRequest 
{
    ContentBody = "test",
    BucketName = "bucket",
    Key = "item-key"
};

por.Metadata.Add("UnicodeValue","拢");

s3c.PutObject(por);

Commenting out por.Metadata.Add("UnicodeValue","拢"); makes the call succeed

Context


I store metadata about objects, and incoming name is one of them and that can be any Unicode

Your Environment

  • AWSSDK.Core version used:
  • Service assembly and version used: AWSSDK.S3 3.3.110.55
  • Operating System and version: Windows 10
  • Visual Studio version: LINQPad 5
  • Targeted .NET platform:
bug

Most helpful comment

Version 3.3.110.66 of AWSSDK.S3 has been released with the fix. Thanks for reporting the issue.

All 4 comments

Looks like an issue with the SDK not encoding non-ascii characters.

https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/S3/Custom/Util/AmazonS3Util.cs#L329-L333

Version 3.3.110.66 of AWSSDK.S3 has been released with the fix. Thanks for reporting the issue.

Thank you @normj !
Noticed the same issue with the toolkit, so raised the same issue there:
https://github.com/aws/aws-toolkit-visual-studio/issues/91

We had to revert this change in the version 3.3.111.1 of AWSSDK.S3 because it was causing a breaking change to user using the S3 encryption client or users that were encoding the metadata values themselves. https://github.com/aws/aws-sdk-net/issues/1617

We did add a new static property called EnableUnicodeEncodingForObjectMetadata on the Amazon.S3. AWSConfigsS3 class that if you set to true will encode the non-ascii characters.

Was this page helpful?
0 / 5 - 0 ratings