简体   繁体   English

如何将现有对象复制到同一路径 Amazon S3

[英]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嗨,我想将现有对象复制到 AWS S3 中的同一路径,但出现以下异常

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.我正在使用 Apache camel S3,我该如何解决这个问题。 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=[])发送请求: DefaultSdkHttpFullRequest(httpMethod=PUT, protocol=https, host=, port=443, encodedPath=, headers=[amz-sdk-invocation-id, User-Agent, x-amz-copy-source, x-amz-元指令、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.如何将现有对象复制到同一路径而不会出现此错误。

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但我认为,应该有一些方法可以通过 API 复制现有对象,因为我可以通过 aws-cli 做同样的事情

Did you look at the copyObject operation in the Apache Camel AWS2 S3 component?您是否查看过 Apache Camel AWS2 S3 组件中的 copyObject 操作? https://camel.apache.org/components/3.17.x/aws2-s3-component.html#_s3_producer_operation_examples https://camel.apache.org/components/3.17.x/aws2-s3-component.html#_s3_producer_operation_examples

There is an example related to headers needed to make the Copy Object operation works.有一个与使复制对象操作正常工作所需的标头相关的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM