简体   繁体   English

使用自定义版本ID将对象上传到Amazon S3

[英]Upload an object to Amazon S3 with custom version id

I want to upload an object to Amazon versioned bucket (using Java AWS SDK) and set a custom version to this object (goal is to set the same version to all objects, uploaded at once) 我想将一个对象上传到Amazon版本存储桶(使用Java AWS开发工具包)并为此对象设置自定义版本(目标是为所有对象设置相同的版本,一次上传)

PutObjectResult por = amazonS3Client.putObject(...);
por.setVersionId("custom_version");

So, is it the right way to set a version to the uploaded object? 那么,为上传对象设置版本的正确方法是吗?

Does this code lead to 2 separate requests to Amazon? 此代码是否会导致向Amazon发出2个单独的请求?

What if Internet is broken while por.setVersionId(..) is being called? 如果在调用por.setVersionId(..)时Internet断开了怎么办?

Why por.setVersionId(..) does not throw an exception such as SdkClientException if this method really is trying to set a version ID on Amazon server? 如果por.setVersionId(..)确实尝试在Amazon服务器上设置版本ID,为什么它不会引发诸如SdkClientException之类的异常?

setVersionId would be something the SDK library itself uses to populate the versionId returned by the service when the object is created, so that you can retrieve it if you want to know what it is. setVersionId将是SDK库本身用来填充创建对象时服务返回的versionId的东西,以便在您想知道它是什么时可以对其进行检索。

Version IDs in S3 are system-generated opaque strings that uniquely identify a specific version of an object. S3中的版本ID是系统生成的不透明字符串,可唯一标识对象的特定版本。 You can't assign them. 您无法分配它们。

The documentation uses some unfortunate examples like "111111" and "222222," which do not resemble real version-ids. 文档使用了一些不幸的示例,例如“ 111111”和“ 222222”,它们与真实的版本ID并不相似。 There's a better example further down the page, where you'll find this: 页面下方还有一个更好的示例,您将在其中找到:

Unique version IDs are randomly generated, Unicode, UTF-8 encoded, URL-ready, opaque strings that are at most 1024 bytes long. 唯一的版本ID是随机生成的,是Unicode,UTF-8编码,URL就绪,不透明的字符串,最长为1024个字节。 An example version ID is 3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo. 示例版本ID是3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo.

Only Amazon S3 generates version IDs. 仅Amazon S3生成版本ID。

They cannot be edited. 它们无法编辑。

You don't get an error here because all this method does is set the versionId inside the PutObjectResult object in local memory after the upload has finished. 您不会在这里收到错误消息,因为上传完成后,此方法所做的全部工作就是在本地内存中的PutObjectResult对象内设置versionId。 It succeeds, but serves no purpose. 它成功了,但毫无用处。

To store user-defined metadata with objects, such as your release/version-id, you'd need to use object metadata ( x-amz-meta-* ) or the new object tagging feature in S3. 要将用户定义的元数据与对象(例如您的release / version-id)存储在一起,您需要使用对象元数据( x-amz-meta-* )或S3中的新对象标记功能。

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

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