英文:
check existance of object after uploading it to S3
问题
我想要检查一个对象是否在成功上传到S3后立刻上传。
PutObjectRequest putObjReq = new PutObjectRequest(bucketName, s3Key, tmpArchivePath.toFile());
Upload upload = transferManager.upload(putObjReq);
upload.waitForCompletion();
boolean fileExistsAfter = s3Client.doesObjectExist(bucketName, s3Key);
这段代码总是返回true,即使对象没有成功上传。我认为这是因为事件ual Consistency,例如:当s3Key以/开头时,它不是一个有效的键,所以对象不会被上传,但它仍然返回true。
英文:
I want to check if an object us successfuly uploaded to S3 just after uploading it.
PutObjectRequest putObjReq = new PutObjectRequest(bucketName, s3Key, tmpArchivePath.toFile());
Upload upload = transferManager.upload(putObjReq);
upload.waitForCompletion();
boolean fileExistsAfter = s3Client.doesObjectExist(bucketName, s3Key);
that returns always true ,even if the object is not successfully uploaded. I think that is because of the Eventual Consistency,
example:
when the s3Key starts with / , it is not a valid key ,so the object will not be uploaded however it returns true
答案1
得分: 1
Your code is working correctly.
When you upload to a key such as /dog.png
, you do indeed get an S3 object with the key /dog.png
. You can see this if you run aws s3 ls s3://mybucket//
(with extra trailing slash) instead of aws s3 ls s3://mybucket/
. You can also verify this by issuing a HeadObject request for the key /dog.png
, which is effectively what the doesObjectExist()
method does.
To verify the object exists using the awscli, run:
aws s3api head-object --bucket mybucket --key /dog.png
So the upload succeeds and doesObjectExist()
correctly returns true.
As a general rule, you probably want to avoid leading slash because it is confusing for people.
英文:
Your code is working correctly.
When you upload to a key such as /dog.png
, you do indeed get an S3 object with the key /dog.png
. You can see this if you run aws s3 ls s3://mybucket//
(with extra trailing slash) instead of aws s3 ls s3://mybucket/
. You can also verify this by issuing a HeadObject request for the key /dog.png
, which is effectively what the doesObjectExist()
method does.
To verify the object exists using the awscli, run:
aws s3api head-object --bucket mybucket --key /dog.png
So the upload succeeds and doesObjectExist()
correctly returns true.
As a general rule, you probably want to avoid leading slash because it is confusing for people.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论