PUT Object - Copy
API Description
You can use this API to create a copy for an object in a specified bucket.
Method Definition
1. ObsClient->copyObject(array $parameter) 2. ObsClient->copyObjectAsync(array $parameter, callable $callback)
Request Parameter
| Field | Type | Optional or Mandatory | Description | 
|---|---|---|---|
| Bucket | string | Mandatory | Target bucket name | 
| Key | string | Mandatory | Target object name | 
| ACL | string | Optional | Pre-defined access control policy specified during object copy | 
| StorageClass | string | Optional | Storage class of the object. Possible values are: | 
| 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 exception is thrown. | 
| CopySourceIfModifiedSince | string or \DateTime | Optional | Copies the source object if it is changed after the time specified by this parameter; otherwise, an exception is thrown. If this parameter value is a character string, it 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 exception is thrown. | 
| CopySourceIfUnmodifiedSince | string or \DateTime | Optional | Copies the source object if it is changed before the time specified by this parameter; otherwise, an exception is thrown. If this parameter value is a character string, it 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. | 
| Expires | string | Optional | Rewrites the Expires header in the response. | 
| MetadataDirective | string | Optional | |
| Metadata | associative array | 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 | Master key used to encrypt the target object in SSE-KMS mode. The value can be null. | 
| SseC | string | Optional | Algorithm used to encrypt the target object in SSE-C mode. The value can be: 
 | 
| SseCKey | string | Optional | Key used to encrypt the target object in SSE-C mode, which is calculated by using AES-256 | 
| 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, which is calculated by using AES-256 | 
 
 
   - 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
| Field | Type | Description | 
|---|---|---|
| HttpStatusCode | integer | HTTP status code | 
| Reason | string | Reason 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 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. | 
| SseKms | string | Algorithm used in SSE-KMS encryption | 
| SseKmsKey | string | Master key used in SSE-KMS encryption | 
| SseC | string | Algorithm used in SSE-C encryption | 
| SseCKeyMd5 | string | MD5 value of the key used in SSE-C encryption | 
Sample Code
try{ $resp = $obsClient -> copyObject([ 'Bucket' => 'bucketname', 'Key' => 'objectkey', 'CopySource' => 'srcbucketname/srcobjectkey', 'Metadata' => ['meta1' => 'value1'] ]); printf("RequestId:%s\n", $resp['RequestId']); printf("ETag:%s\n", $resp['ETag']); printf("VersionId:%s\n", $resp['VersionId']); printf("CopySourceVersionId:%s\n", $resp['CopySourceVersionId']); printf("LastModified:%s\n", $resp['LastModified']); }catch (Obs\Common\ObsException $obsException){ printf("ExceptionCode:%s\n", $obsException->getExceptionCode()); printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage()); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.
 
    