Rename and Move Operations on an Object
To rename and to move an object, we will be using the same rename_object() SDK method. The Bucket reference used in the below code snippet is the component instance.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
key | String | The original name of the object that you need to rename |
destination | String | The new name that you rename the object with |
-
You need to provide the complete object name, along with the path for both sourceObject and destObject values.
-
For example, if you have file named “kitten.png” in the path pictures/puppy, and you need to move or rename the file to pictures/kitten path, then:
key value will be ‘pictures/puppy/kitten.png’
destination value will be ‘pictures/kitten/kitten.png’
Rename an Object
Using the rename_object() SDK method you can rename objects present in a bucket.
-
You cannot rename objects in a bucket that has Versioning enabled.
-
The following characters including space are not supported when you create a path or an object: double quote, both angular brackets, hashtag, backward slash and pipe symbol.
copyrename_res = bucket.rename_object("sam/out/sample.txt","sam/out/update_sample.txt") print(rename_res)
Example Response
copy{ "current_key": "sam/out/sample.txt", "message": "Rename successful", "rename_to": "sam/out/update_sample.txt" }
Move an Object
Using the rename_object() SDK method, we can move the object from one path to another within a bucket. The Bucket reference used in the below code snippet is the component instance.
copyrename_res = bucket.rename_object("sam/out/sample.txt","output/sample.txt") print(rename_res)
Example Response
copy{ "current_key": "sam/out/sample.txt", "message": "Rename successful", "rename_to": "sutput/sample.txt" }
Last Updated 2025-05-30 16:54:59 +0530 +0530
Yes
No
Send your feedback to us