Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How copy an existing object to same path Amazon S3

Hi I want to copy an existing object to same path in AWS S3 and I am getting following exception

This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class, website redirect location or encryption attributes

I am using Apache camel S3, how can i resolve this. After searching, i found there is a request header which we can use to replace the existing file but it is not working


// multiple other attempts also present, I am not sure which header will work

exchange.`in`.headers[AWS2S3Constants.METADATA] = mutableMapOf(
            "x-amz-metadata-directive" to "REPLACE",
            "x-amz-meta-directive" to "REPLACE",
            "metadata-directive" to "REPLACE",
            "MetadataDirective" to "REPLACE"
        )

I have logged in the request.

Sending Request: DefaultSdkHttpFullRequest(httpMethod=PUT, protocol=https, host=, port=443, encodedPath=, headers=[amz-sdk-invocation-id, User-Agent, x-amz-copy-source, x-amz-meta-directive, x-amz-meta-metadata-directive, x-amz-meta-MetadataDirective, x-amz-meta-x-amz-metadata-directive], queryParameters=[])

But it is not working. how can i copy an existing object to same path without getting this error.

like image 586
Zakir saifi Avatar asked Dec 12 '25 04:12

Zakir saifi


1 Answers

I end up changing the filename by suffixing it with a timestamp. Now I am no longer getting the error.

But I think, there should be some way to copy existing objects via API, since I am able to do same via aws-cli

like image 125
Zakir saifi Avatar answered Dec 13 '25 18:12

Zakir saifi