PUT Object - Copy

Last updated: 2018-09-26 18:27:38

PDF

Description

The PUT Object - Copy request copies a file from the source path to the target path. It is recommended that the file size is 1M to 5G. For files larger than 5G, please use the multipart upload Upload - Copy. The file metadata and ACL can be modified during the copy process.
Users can use this API to move files, rename files, modify file attributes, and create copies.

Version

By default, version control is enabled on the target bucket, and COS generates a unique version ID for the object being copied. This version ID is different from the version ID of the source object. COS returns the version ID of the copied object in the response header in the x-cos-version-id response.
If you do not enable or paused version control in the target bucket, the version ID generated by COS is always null.

Note:
When copying across accounts, you need to set the permissions of the copied files to
read, or grant access to the target account.

Request

Request example:

PUT /destinationObject HTTP/1.1
Host: <Bucketname-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Authorization: Auth String
x-cos-copy-source: <Bucketname>-<APPID>.cos.<Region>.myqcloud.com/filepath

Authorization: Auth String (See Request Signature )

Request Line

PUT /{ObjectName} HTTP/1.1

The API accepts PUT requests.

Request Headers

Common Headers

The implementation of this request operation uses the common request header. For details on the common request header, see the Common Request Header.

Non-common Headers

Name Type Required Description
x-cos-copy-source string is the Source file URL path, which can be specified by the versionid sub-resource
x-cos-metadata-directive string No Whether to copy metadata. Values: Copy (default), Replaced. For Copy, the user metadata information in the Header is ignored and copied directly; if it is marked as Replaced, the metadata is modified by the Header information. When the target path is the same as the original path, that is, when the user tries to modify the metadata, it must be Replaced.
x-cos-copy-source-If-Modified-Since string No When an Object is modified after a specified time, the operation is performed, otherwise it returns 412. It can be used with x-cos-copy-source-If-None-Match. Conflicts occurs for conjunction with other conditions
x-cos-copy-source-If-Unmodified-Since string No When the Object is not modified after the specified time, the operation is performed, otherwise it returns 412. It can be used with x-cos-copy-source-If-Match. Conflicts occurs for conjunction with other conditions
x-cos-copy-source-If-Match string No When the Etag of the Object matches the given, the operation is performed, otherwise it returns 412. Can be used with x-cos-copy-source-If-Unmodified-Since to return conflicts in conjunction with other conditions
x-cos-copy-source-If-None-Match string No When the Etag of the Object is inconsistent with the given, the operation is performed, otherwise it returns 412. Can be used with x-cos-copy-source-If-Modified-Since to return conflicts in conjunction with other conditions
x-cos-storage-class string No Set the storage level of Object, enumeration value: STANDARD, STANDARD_IA, default value: STANDARD
x-cos-acl string No Defines the ACL property of the Object. Valid values: private, public-read-write, public-read; Default: private
x-cos-grant-read string No Grant READ access to the specified persons. Format: x-cos-grant-read: id=" ",id=" ";
For a sub-account, id="qcs::cam::uin/\:uin/< SubUin>",
For a root account, id="qcs::cam::uin/\:uin/\"
x-cos-grant-write string No Grant WRITE access to the specified persons. Format: x-cos-grant-read: id=" ",id=" ";
For a sub-account, id="qcs::cam::uin/\:uin/< SubUin>",
For a root account, id="qcs::cam::uin/\:uin/\"
x-cos-grant-full-control string No Grant READ and WRITE access to the specified persons. Format: x-cos-grant-read: id=" ",id=" ";
For a sub-account, id="qcs::cam::uin/\:uin/< SubUin>",
For a root account, id="qcs::cam::uin/\:uin/\"
x-cos-meta-* string No Other custom file headers

server encryption related headers

The request operation specifies the protection strategy for applying data encryption when Tencent Cloud COS is in data storage. Tencent Cloud COS will help you automatically encrypt data as it is written to the data center and automatically decrypt it when you access it. AES-256 encryption is now supported for data using the Tencent Cloud COS Master Key. If you need to enable server-side encryption for your data, you need to pass in the following header:

Name Description Type Required
x-cos-server-side-encryption Specifies how the server is enabled for server-side encryption. Use COS master key encryption to fill in: AES256 String For encryption, yes

Request Body

The request request body is empty.

Response

Response header

Common response header

The response uses a common response header. For a detailed description of the common response header, see the Common Response Header section.

API response header

Name Description Type
x-cos-version-id The version of the replicated object in the target bucket. String
x-cos-server-side-encryption If the object is stored by COS-managed server-side encryption, the response will contain the value of this header and the encryption algorithm used, AES256. String

Response body

The copy is successful and the response body is returned.

<CopyObjectResult>
    <ETag>"ba82b57cfdfda8bd17ad4e5879ebb4fe"</ETag>
    <LastModified>2017-08-04T02:41:45</LastModified>
</CopyObjectResult>

The specific data is described as follows:

Node Name (Keyword) Parent Node Description Type Required
ETag None Returns the MD5 algorithm check value of the file. The value of ETag can be used to check if the contents of the Object have been changed string

Sample Code

Request

PUT /222.txt HTTP/1.1
Host: bucket1-1252443703.cos.ap-beijing.myqcloud.com
Date: Fri, 04 Aug 2017 02:41:45 GMT
Connection: keep-alive Accept-Encoding: gzip, deflate Accept: */*
User-Agent: python-requests/2.12.4
Authorization: q-sign-algorithm=sha1&q-ak=AKID15IsskiBQKTZbAo6WhgcBqVls9SmuG00&q-sign-time=1480932292;1981012292&q-key-time=1480932292;1981012292&q-url-param-list=&q-header-list=host&q-signature=eacefe8e2a0dc8a18741d9a29707b1dfa5aa47cc
x-cos-copy-source: bucket2-1252443704.cos.ap-beijing.myqcloud.com/1.txt
Content-Length: 0

Response

HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 133
Connection: keep-alive
Date: Fri, 04 Aug 2017 02:41:45 GMT
Server: tencent-cos
x-cos-request-id: NTk4M2RlZTlfZDRiMDM1MGFfYTA1ZV8xMzNlYw==

<CopyObjectResult>
    <ETag>"ba82b57cfdfda8bd17ad4e5879ebb4fe"</ETag>
    <LastModified>2017-08-04T02:41:45</LastModified>
</CopyObjectResult>