更新时间:2021-03-18 GMT+08:00
分享

复制对象

功能说明

为指定桶中的对象创建一个副本。

方法定义

ObsClient.copyObject

请求参数

字段名

类型

约束

说明

Bucket

String

必选

目标桶名。

Key

String

必选

目标对象名。

ACL

String

可选

复制对象时可指定的预定义访问策略

StorageClass

String

可选

复制时设置对象的存储类型

CopySource

String

必选

指定源桶、源对象和源对象版本号(可为空)的参数,格式:源桶名/源对象名?versionId=源对象版本号。

CopySourceIfMatch

String

可选

如果源对象的ETag值与该参数值相同,则进行复制,否则返回异常码。

CopySourceIfModifiedSince

String

可选

如果源对象的修改时间晚于该参数值指定的时间,则进行复制,否则返回异常码。该参数值必须符合http://www.ietf.org/rfc/rfc2616.txt规定的HTTP时间格式。

CopySourceIfNoneMatch

String

可选

如果源对象的ETag值与该参数值不相同,则进行复制,否则返回异常码。

CopySourceIfUnmodifiedSince

String

可选

如果源对象的修改时间早于该参数值指定的时间,则进行复制,否则返回异常码。该参数值必须符合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头。

Expires

String

可选

复制时重写响应中的Expires头。

MetadataDirective

String

可选

复制策略

Metadata

Object

可选

目标对象的自定义元数据。

WebsiteRedirectLocation

String

可选

当桶设置了Website配置,该参数指明对象的重定向地址。

SuccessActionRedirect

String

可选

复制对象成功后的重定向的地址。

SseKms

String

可选

以SSE-KMS方式加密目标对象,支持的值:

  • kms

SseKmsKey

String

可选

SSE-KMS方式下加密目标对象的主密钥,可为空。

SseC

String

可选

以SSE-C方式加密目标对象,支持的值:

  • AES256

SseCKey

Buffer

可选

SSE-C方式下加密目标对象的密钥,由AES256算法算出。

CopySourceSseC

String

可选

以SSE-C方式解密源对象,支持的值:

  • AES256

CopySourceSseCKey

Buffer

可选

SSE-C方式下解密源对象的密钥,由AES256算法算出。

  • 如果包含CopySourceIfUnmodifiedSince并且不符合,或者包含CopySourceIfMatch并且不符合,或者包含CopySourceIfModifiedSince并且不符合,或者包含CopySourceIfNoneMatch并且不符合,抛出异常中HTTP状态码为:412 precondition failed。
  • CopySourceIfModifiedSince和CopySourceIfNoneMatch可以一起使用;CopySourceIfUnmodifiedSince和CopySourceIfMatch可以一起使用。

返回结果(InterfaceResult)

字段名

类型

说明

RequestId

String

OBS服务端返回的请求ID。

ETag

String

目标对象的ETag值。

LastModified

String

目标对象的最近一次修改时间。

VersionId

String

目标对象的版本号,如果目标桶未开启多版本状态则该值为空。

CopySourceVersionId

String

源对象的版本号,如果源桶未开启多版本状态则该值为空。

SseKms

String

SSE-KMS方式的算法。

SseKmsKey

String

SSE-KMS方式的主密钥。

SseC

String

SSE-C方式的算法。

SseCKeyMd5

String

SSE-C方式的密钥的MD5值。

代码样例

obsClient.copyObject({
       Bucket:'bucketname',
       Key:'objectkey',
       CopySource:'srcbucketname/srcobjectkey',
       Metadata:{meta1:'value1'}
},(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);
              }
       }
});
分享:

    相关文档

    相关产品