Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update S3 file remove meta data

Tags:

amazon-s3

We hosted our script files in S3 with cloudfront. Whenever i update older js file with a new js file, it removes the metadata of a file. I have to reenter them again.

Is there any way to fix it?

like image 336
Fizer Khan Avatar asked Oct 21 '25 03:10

Fizer Khan


1 Answers

It can't be fixed, because the behavior you describe isn't actually broken -- it's by design.

The following may sound like a word game, but the finer points of the terminology explain the issue.

Objects can't be "updated" in S3 -- they can only be overwritten. When you upload a new version, you are not updating the object, you're replacing it, so, technically, that's a different object... with the same key (path). As metadata is a property of the object (not a property of the key), a different object would have different metadata, so when an object is uploaded, that metadata has to be set.

In fact, to put an extremely fine point to it, when you "edit" object metadata in the console, you're still not technically updating the object -- you're actually making a copy of the object's payload, creating yet another new object, and the new object has the metadata you want. This new object (same payload, different metadata) overwrites the former object (same payload, original or empty metadata). S3 does the payload copy internally, so the body isn't actually downloaded and re-uploaded.

The workaround would be to use something to do the uploads that will either use your desired metadata, or fetch the old object's metadata, as appropriate, and use it to create the new object. That "something" could be a tool you write or a tool you find.

like image 130
Michael - sqlbot Avatar answered Oct 25 '25 05:10

Michael - sqlbot