检查S3复制操作是否成功? [英] Checking for successful S3 copy operation?

查看:87
本文介绍了检查S3复制操作是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Amazon S3 Java API实施移动操作.

I'm trying to implement a move operation using the Amazon S3 Java API.

我遇到的问题是

The problem I am having is that the CopyObjectResult object returned by the AmazonS3Client.copyObject method doesn't seem to have a clear indicator about wiether the operation was successful or not.

鉴于此操作之后,我将要删除文件,所以我想确保操作成功.

Given that after this operation I am going to be deleting a file, I'd want to make sure that the operation was successful.

有什么建议吗?

推荐答案

这就是我最终要做的事情,

This is what I ended up doing,

def s3 = createS3Client(credentials)
def originalMeta = s3.getObjectMetadata(originalBucketName, key)
s3.copyObject(originalBucketName, key, newBucketName, newKey)
def newMeta = s3.getObjectMetadata(newBucketName, newKey)

// check that md5 matches to confirm this operation was successful
return originalMeta.contentMD5 == newMeta.contentMD5

请注意,这是Groovy代码,但与Java代码的工作方式极为相似.

Note that this is Groovy code, but it is extremely similar to how the Java code would work.

我不喜欢另外进行两次操作来检查元数据,所以如果有什么方法可以更有效地进行此操作,请告诉我.

I don't like having to make two additional operations to check the metadata, so if there is anyway to do this more efficiently let me know.

这篇关于检查S3复制操作是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆