question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to update metadata in copyObject

See original GitHub issue

Hello,

I am trying to use copyObject to copy a file over itself while updating lastModified on it. However, this fails with this error:

S3Error: 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’ve noticed that some of the other client libraries do include metadata fields in their copyObject - however I can also see how adding a parameter would introduce a potentially breaking change.

I can work with either of these two solutions:

  • Update lastModified when copying an object onto itself
  • Adding a parameter for new metadata
  • Adding an overflow method that replaces the conditions parameter with an object (an example):
const conds = new Minio.CopyConditions();
const options = {
    conditions: conds,
    metadata: {
        lastModified: new Date()
    }
}
client.copyObject('bucket', 'prefix/file', '/bucket/prefix/file', options, callback);

For now I will have to stick with the download/reupload workaround - but using copyObject will be far more efficient.

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Chhunnengcommented, Jun 23, 2021

The code below is Python.

result = client.stat_object("bucket", "object.txt")
current_metadata = {}
for key in result.metadata:
    if "X-Amz-Meta" in key:
        current_metadata[key.split("-")[-1]] = result.metadata[key]
client.copy_object(
    "bucket",
    "object.txt",
    CopySource("bucket", "object.txt"),
    metadata={**current_metadata, "Age": "121212",
              "Owner": "me", "money": "1M $"},
    metadata_directive=REPLACE
)
result = client.stat_object("bucket", "object.txt")

Now I am using this method to update metadata. I hope we will have the function to update metadata directly.

0reactions
balamuruganacommented, Apr 4, 2022

Why is this issue relevant to current minio-py?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No way to update metadata in copyObject · Issue #1192 - GitHub
Hello, I am trying to use copyObject to copy a file over itself while updating lastModified on it. However, this fails with this...
Read more >
How to update metadata on an existing object in s3 using ...
My metadata is updated and my original file does not get overwritten and deleted. I used the documentation from here. So my PUT...
Read more >
CopyObject - Amazon Simple Storage Service
When copying an object, you can preserve all metadata (default) or specify new metadata. However, the ACL is not preserved and is set...
Read more >
Amazon S3 - Copy object(s)
... the original ones, move objects across Amazon S3 locations and update object metadata by copying original objects to new ones that contain...
Read more >
Creating Tables In A S3 Bucket Issues - Ahana Cloud
Copy the object over again using S3 command line or python script. Note: Since S3 is an immutable store, so there is no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found