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.
If you have enabled Versioning for your bucket, then you need to pass the version_id 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. |
version_id | String | An Optional parameter. Will hold the unique version ID of the object, if Versioning is enabled. |
throw_err | Boolean | An Optional parameter. If you set this parameter as "true", then it will throw an error when the bucket is not found in the project. The default value is "false" |
copyhead_object_res = bucket.head_object( "sam/out/sample.txt", 'version_id', throw_err=False) print(head_object_res)
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 in Stratus. |
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-05-30 16:54:59 +0530 +0530
Yes
No
Send your feedback to us
Skip
Submit