Reputation: 49649
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.
Any suggestions?
Upvotes: 8
Views: 5890
Reputation: 1423
AWS documentation says
The source and destination ETag is identical for a successfully copied
Upvotes: 0
Reputation: 49649
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
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.
Upvotes: 6
Reputation: 1817
I'm pretty sure you can just use CopyObjectResult object's getETag method to confirm that, after created, it has a valid ETag, as was made in the CopyObjectRequest setETag method.
getETag
public String getETag()
Gets the ETag value for the new object that was created in the associated CopyObjectRequest. Returns: The ETag value for the new object. See Also: setETag(String) setETag
public void setETag(String etag)
Sets the ETag value for the new object that was created from the associated copy object request. Parameters: etag - The ETag value for the new object. See Also: getETag()
Always trust the data.
Been a year since I did a similar function with the Amazon PhP SDK a couple years ago, but it should work.
Upvotes: 1