Copying an Object
API Description
You can use this API to create a copy for an object in a specified bucket.
Method Definition
ObsClient.copyObject(sourceBucketName, sourceObjectKey, destBucketName, destObjectKey, metadata, headers, versionId)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
sourceBucketName |
str |
Mandatory |
Source bucket name |
|
sourceObjectKey |
str |
Mandatory |
Source object name |
|
versionId |
str |
Optional |
Source object version ID |
|
destBucketName |
str |
Mandatory |
Target bucket name |
|
destObjectKey |
str |
Mandatory |
Target object name |
|
metadata |
dict |
Optional |
Customized metadata of the target object |
|
headers |
Optional |
Additional header of the request for copying an object |
Returned Results
|
Type |
Description |
|---|---|
|
SDK common result object |
|
GetResult.body Type |
Description |
|---|---|
|
Response result of the request for copying an object |
Sample Code
try:
resp = obsClient.copyObject('sourcebucketname', 'sourceobjectkey', 'destbucketname', 'destobjectkey', metadata={'meta1' : 'value1'})
if resp.status < 300:
print('requestId:', resp.requestId)
print('etag:', resp.body.etag)
print('lastModified:', resp.body.lastModified)
print('versionId:', resp.body.versionId)
print('copySourceVersionId:', resp.body.copySourceVersionId)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc())
Last Article: Creating a Folder
Next Article: Deleting an Object
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.