PUT Object - Copy
API Description
You can use this API to create a copy for an object in a specified bucket.
Method Definition
ObsClient.copyObject
Request Parameter
Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
Bucket | String | Mandatory | Target bucket name |
Key | String | Mandatory | Target object name |
RequestDate | String or Date | Optional | Request time NOTE: When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards. |
ACL | String | Optional | Pre-defined access control policy specified during object creation |
StorageClass | String | Optional | Storage class, which can be specified during the object creation |
CopySource | String | Mandatory | Parameter used to specify the source bucket, source object, and source object version ID which can be null. It is in the format of SourceBucketName/SourceObjectName?versionId=SourceObjectVersionId. |
CopySourceIfMatch | String | Optional | Copies the source object if its ETag is the same as the one specified by this parameter; otherwise, an error code is returned. |
CopySourceIfModifiedSince | String | Optional | Copies the source object if it is changed after the time specified by this parameter; otherwise, an error code is returned. The value must conform to the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. |
CopySourceIfNoneMatch | String | Optional | Copies the source object if its ETag is different from the one specified by this parameter; otherwise, an error code is returned. |
CopySourceIfUnmodifiedSince | String | Optional | Copies the source object if it is changed before the time specified by this parameter; otherwise, an error code is returned. The value must conform to the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. |
CacheControl | String | Optional | Rewrites the Cache-Control header in the response. |
ContentDisposition | String | Optional | Rewrites the Content-Disposition header in the response. |
ContentEncoding | String | Optional | Rewrites the Content-Encoding header in the response. |
ContentLanguage | String | Optional | Rewrites the Content-Language header in the response. |
ContentType | String | Optional | Rewrites the Content-Type header in the response. For details about the common content types, see Configuring, Editing, and Viewing Object Metadata. |
Expires | String | Optional | Rewrites the Expires header in the response. |
MetadataDirective | String | Optional | |
Metadata | Object | Optional | Customized metadata of the target object |
WebsiteRedirectLocation | String | Optional | Location where the object is redirected to, when the bucket is configured with website hosting. |
SseKms | String | Optional | Algorithm used to encrypt the target object in SSE-KMS mode. The value can be:
|
SseKmsKey | String | Optional | ID of the master key used in SSE-KMS encryption. The value can be null. To obtain the key ID, see Viewing a Key. |
SseC | String | Optional | Algorithm used to encrypt the target object in SSE-C mode. The value can be:
|
SseCKey | String | Optional | Custom key used in SSE-C encryption. The value is a Base64-encoded 256-bit key. |
CopySourceSseC | String | Optional | Algorithm used to decrypt the source object in SSE-C mode. The value can be:
|
CopySourceSseCKey | String | Optional | Key used to decrypt the source object in SSE-C mode |

- If the object copy request includes CopySourceIfUnmodifiedSince, CopySourceIfMatch, CopySourceIfModifiedSince, or CopySourceIfNoneMatch, and the specified condition is not met, an exception will be thrown with HTTP status code 412 Precondition Failed returned.
- CopySourceIfModifiedSince and CopySourceIfNoneMatch can be used together. So do CopySourceIfUnmodifiedSince and CopySourceIfMatch.
Returned Result (InterfaceResult)
Field | Type | Description |
|---|---|---|
RequestId | String | Request ID returned by the OBS server |
ETag | String | ETag of the target object |
LastModified | String | Time when the last modification was made to the target object |
VersionId | String | Version ID of the target object. This field is null if versioning is not enabled for the target bucket. |
CopySourceVersionId | String | Version ID of the source object. This field is null if versioning is not enabled for the source bucket. |
Sample Code
obsClient.copyObject({
Bucket:'bucketname',
Key:'objectkey',
CopySource:'srcbucketname/srcobjectkey',
Metadata:{meta1:'value1'}
},function (err, result) {
if(err){
console.error('Error-->' + err);
}else{
if(result.CommonMsg.Status < 300){
console.log('RequestId-->' + result.InterfaceResult.RequestId);
console.log('ETag-->' + result.InterfaceResult.ETag);
console.log('VersionId-->' + result.InterfaceResult.VersionId);
console.log('CopySourceVersionId-->' + result.InterfaceResult.CopySourceVersionId);
console.log('LastModified-->' + result.InterfaceResult.LastModified);
}else{
console.log('Code-->' + result.CommonMsg.Code);
console.log('Message-->' + result.CommonMsg.Message);
}
}
}); Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.

