Home > OS >  S3 Tagging Error - The TagValue you have provided is invalid
S3 Tagging Error - The TagValue you have provided is invalid

Time:10-02

We are using tagging in S3 for some files, however, if we use an "& " character in the value of the key value pair, I get the following error

"The TagValue you have provided is invalid"

Any ideas on how to get around this to work in S3?

Here is the code we are using with the AWS Sdk

    var documents = await GetDocumentsAsync(clientDoc.ClientId);
    var objectKey = $"{clientDoc.ClientId}/{clientDoc.FileName}";

    var newTagSet = new Tagging
    {
        TagSet = new List<Tag>{
            new Tag { Key = "ClientName", Value = clientDoc.ClientName ?? "" }
        }
    };

    var putObjTagsRequest = new PutObjectTaggingRequest()
    {
        BucketName = _systemConfig.S3BucketName,
        Key = objectKey,
        Tagging = newTagSet
    };

    var response = await s3Client.PutObjectTaggingAsync(putObjTagsRequest);

CodePudding user response:

Tags must follow the following regex ^([\p{L}\p{Z}\p{N}_.:/= \-@]*)$

https://docs.aws.amazon.com/directoryservice/latest/devguide/API_Tag.html

The only way to 'get around it' would be to not use the character. You could encode it but at that point... probably best to just not use it.

  • Related