简体   繁体   English

更新S3文件删除元数据

[英]Update S3 file remove meta data

We hosted our script files in S3 with cloudfront. 我们将脚本文件托管在带有Cloudfront的S3中。 Whenever i update older js file with a new js file, it removes the metadata of a file. 每当我用新的js文件更新较旧的js文件时,它都会删除文件的元数据。 I have to reenter them again. 我必须重新输入一次。

Is there any way to fix it? 有什么办法可以解决?

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. 在S3中无法“更新”对象-它们只能被覆盖。 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. S3在内部进行有效负载复制,因此实际上并未下载并重新加载主体。

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. “东西”可以是您编写的工具,也可以是找到的工具。

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

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