Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Underscore converted to hyphen while put it as metadata using amazon-sdk #459

@itaimarts

Description

@itaimarts

Hi,
When try to put object with metadata that include underscore(the metadata include underscore) we got the underscore converted to hyphen.
The same code in Amazon will return the metadata with underscore - not converted.

for example:
we put map of string as metadata - the "__key1" will convert to "--key1"

public class MyAwsS3Tester {

    public static final String IP = "10.0.0.24";
    public static final String BUCKET_NAME = "zanavi-test";

    public static void main(String[] args) {
        AmazonS3 s3 = AmazonS3ClientBuilder.standard()
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://" + IP + ":4572/", "us-east-1"))
                .disableChunkedEncoding()
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("zanavi", "1234")))
                .build();
        if (s3.doesBucketExistV2(BUCKET_NAME)) {
            System.out.println("bucket zanavi exists");
        }
        else {
            System.out.println("bucket " + BUCKET_NAME + " doesn't exists");
            s3.createBucket(BUCKET_NAME);
        }

        String dummyStr = "dummy-str";

        Map<String, String> myMap = new HashMap<String, String>();
        myMap.put("__key1", "val1");

        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setUserMetadata(myMap);

        InputStream is = new ByteArrayInputStream(dummyStr.getBytes(StandardCharsets.UTF_8));
        s3.putObject(new PutObjectRequest(BUCKET_NAME, "my-key1", is, objectMetadata));

        S3Object getObj = s3.getObject(new GetObjectRequest(BUCKET_NAME, "my-key1"));
        ObjectMetadata objectMetadataResponse = getObj.getObjectMetadata();

        Map<String, String> myMap1 = objectMetadataResponse.getUserMetadata();

        System.out.println("done " + myMap1);
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions