复制对象
功能说明
为指定桶中的对象创建一个副本。
方法定义
1. ObsClient->copyObject(array $parameter) 2. ObsClient->copyObjectAsync(array $parameter, callable $callback)
请求参数
字段名 | 类型 | 约束 | 说明 |
|---|---|---|---|
Bucket | string | 必选 | 目标桶名。 |
Key | string | 必选 | 目标对象名。 |
ACL | string | 可选 | 复制对象时可指定的预定义访问策略。 |
StorageClass | string | 可选 | 复制时设置对象的存储类型。 |
CopySource | string | 必选 | 指定源桶、源对象和源对象版本号(可为空)的参数,格式:源桶名/源对象名?versionId=源对象版本号。 |
CopySourceIfMatch | string | 可选 | 如果源对象的ETag值与该参数值相同,则进行复制,否则抛出异常。 |
CopySourceIfModifiedSince | string 或 \DateTime | 可选 | 如果源对象的修改时间晚于该参数值指定的时间,则进行复制,否则抛出异常。该参数值为字符串时必须符合http://www.ietf.org/rfc/rfc2616.txt规定的HTTP时间格式。 |
CopySourceIfNoneMatch | string | 可选 | 如果源对象的ETag值与该参数值不相同,则进行复制,否则抛出异常。 |
CopySourceIfUnmodifiedSince | string 或 \DateTime | 可选 | 如果源对象的修改时间早于该参数值指定的时间,则进行复制,否则抛出异常。该参数值为字符串时必须符合http://www.ietf.org/rfc/rfc2616.txt规定的HTTP时间格式。 |
CacheControl | string | 可选 | 复制时重写响应中的Cache-Control头。 |
ContentDisposition | string | 可选 | 复制时重写响应中的Content-Disposition头。 |
ContentEncoding | string | 可选 | 复制时重写响应中的Content-Encoding头。 |
ContentLanguage | string | 可选 | 复制时重写响应中的Content-Language头。 |
ContentType | string | 可选 | 复制时重写响应中的Content-Type头。常见的contentType(MIME)列表参见配置、编辑、查看对象元数据。 |
Expires | string | 可选 | 复制时重写响应中的Expires头。 |
MetadataDirective | string | 可选 | 复制策略。 |
Metadata | associative array | 可选 | 目标对象的自定义元数据。 |
WebsiteRedirectLocation | string | 可选 | 当桶设置了Website配置,该参数指明对象的重定向地址。 |
SseKms | string | 可选 | 以SSE-KMS方式加密目标对象,支持的值:
|
SseKmsKey | string | 可选 | SSE-KMS加密方式下使用的KMS主密钥的ID值,为空则默认配置为默认密钥。密钥ID获取方法请参见查看密钥。 |
SseC | string | 可选 | 以SSE-C方式加密目标对象,支持的值:
|
SseCKey | string | 可选 | SSE-C方式下加密的密钥,该密钥需要您自定义,并由256bit的密钥经过base64编码得到。 |
CopySourceSseC | string | 可选 | 以SSE-C方式解密源对象,支持的值:
|
CopySourceSseCKey | string | 可选 | SSE-C方式下解密源对象的密钥,由AES256算法算出。 |

- 如果包含CopySourceIfUnmodifiedSince并且不符合,或者包含CopySourceIfMatch并且不符合,或者包含CopySourceIfModifiedSince并且不符合,或者包含CopySourceIfNoneMatch并且不符合,抛出异常中HTTP状态码为:412 precondition failed。
- CopySourceIfModifiedSince和CopySourceIfNoneMatch可以一起使用;CopySourceIfUnmodifiedSince和CopySourceIfMatch可以一起使用。
返回结果
字段名 | 类型 | 说明 |
|---|---|---|
HttpStatusCode | integer | HTTP状态码。 |
Reason | string | HTTP文本描述。 |
RequestId | string | OBS服务端返回的请求ID。 |
ETag | string | 目标对象的ETag值。 |
LastModified | string | 目标对象的最近一次修改时间。 |
VersionId | string | 目标对象的版本号,如果目标桶未开启多版本状态则该值为空。 |
CopySourceVersionId | string | 源对象的版本号,如果源桶未开启多版本状态则该值为空。 |
SseKms | string | SSE-KMS方式的算法。 |
SseKmsKey | string | SSE-KMS加密方式下使用的KMS主密钥的ID值,为空则默认配置为默认密钥。密钥ID获取方法请参见查看密钥。 |
SseC | string | SSE-C方式的算法。 |
SseCKeyMd5 | string | SSE-C方式的密钥的MD5值。 |
代码样例
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());
} 
