-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to confirm object exist or not? #639
Comments
What you explained is the most idiomatic way. What exactly are you looking for ? |
@harshavardhana Sorry, I have updated the issue. |
@laudukang You would need to do like below boolean found = false;
try {
minioClient.statObject("my-bucketname", "my-objectname");
found = true;
} catch (ErrorResponseException e) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_OBJECT)) {
throw e;
}
}
if (found) {
// Do things when object is found
} else {
// Do things when object is not found
} |
@laudukang Please close the issue, if the above reply is what you are looking for. |
This works a bit better.
|
what about a folder? it throws a NO SUCH KEY exception too! |
@balamurugana I guess there is a delete marker (at least in Go minio client, have not checked in Java), and instead of just returning true, we should check for a delete marker.
|
Hello MinIO devs! After searching for the correct way to check if a MinIO object exists, I stumbled across this thread. @balamurugana suggested the following:
However, in the latest version of MinIO (or more specifically, since release 8.0.0) the ErrorCode enum has been deleted. (See PR #1028 ). Thanks!! - Tabi |
It is same logic like below try {
StatObjectResponse stat = minioClient.statObject(StatObjectArgs.builder().bucket("my-bucketname").object("my-objectname").build());
found = true;
} catch (ErrorResponseException e) {
if (e.response().code() != "NoSuchKey")) {
throw e;
}
} Refer https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html for error codes. If you want enum style error codes, define your own enums and use it here. |
Thanks for the quick reply and the link to the error codes @balamurugana ! |
I have a use case to comfirm a object exist in bucket whether or not, and I can finish the case through the following ways:
MinioClient#statObject, method will throw exception if object not exist, so I can know the object is not exist in minio server
MinioClient#getObject, method will throw exception if object not exist
Is there a better way that I can ensure a object exist in minio server whether or not?
The text was updated successfully, but these errors were encountered: