Check Object Availability

Using this SDK method, you can check if a particular object is present in the bucket, if the user has the required permissions to access the object. The Bucket reference used in the below code snippet is the component instance.

Info: To use this SDK method, you need intialize it with Admin scope. You can learn more about this requirement from this section

If you have enabled Versioning for your bucket, then you need to pass the versionID as the param, to check if a particular version of the object is available.

When you use this SDK method, you will get either of the following responses:

  • true: If the object is available, the specified version is available, and if the user has the relevant permissions to access the objects.
  • false:
    • If the object or the particular version of the object is not available in the bucket.
    • If the user does not have the required permissions to access the object.
    • If the bucket does not exist.

Parameters Used

Parameter Name Data Type Definition
key String A Mandatory parameter. Will hold the complete name of the object.
versionId String An Optional parameter. Will hold the unique version ID of the object, if Versioning is enabled.
throwErr Boolean An Optional parameter. If you set this parameter as "true", then it will throw an error when the object is not found in the project. The default value is "false"
    
copy
Boolean throwErr = true; Boolean headObjectRes = bucket.headObject("sam/out/sample.txt", "versionId", throwErr); System.out.println(headObjectRes);

Possible Errors

Note: If you use the SDK with the throw_err parameter, and the object does not exist, or if you do not have sufficient permissions then you may encounter any of the errors listed below.
Error Code Meaning
404 Not Found. Object Not found.
401 Unauthorized/Access Denied - User doesn't have permission to perform the particular operation.
403 Permission Denied - User does not have permission to access the particular object.

Last Updated 2025-06-20 16:21:48 +0530 +0530