CopyObject
Interface Description
This interface allows you to copy an existing object to another object. The length range of the object files supported is 0-5 GB. You can also use this interface to update the meta. You can use the Replace mode, and the source and destination point to the same file. This interface requires the requester to specify the copy source in the header.
The CopyObject interface supports the cross-region file copy, that is, the source bucket and destination bucket of the copy file may not be in the same region. At present, you can copy the data from other regions to this region only. The cross-region data flow is charged for the data flow generated by the copy during cross-region file copy. For the cross-region charging standards, see Product Pricing.
Request
-
Request syntax
PUT /<ObjectKey> HTTP/1.1 Host: <BucketName>.bj.bcebos.com Date: <Date> Authorization: <AuthorizationString> Content-Length: <ContentLength> Content-Type:text/plain x-bce-copy-source: /SourceBucket/SourceObject x-bce-copy-source-if-match: 3858f62230ac3c915f300c664312c11f x-bce-metadata-directive: <DirectiveString> x-bce-storage-class: <StorageClass>
-
Request parameters
None
-
Request header field
Name Type Description Required? x-bce-copy-source String Source object address Yes x-bce-copy-source-if-match String If the ETag value of the source object is equal to the ETag value provided by the user, you can perform the copy operation. Otherwise, the copy fails. No x-bce-metadata-directive String Is the meta information of the destination object is copied from the source object or passed in by the request? The valid value is copy
andreplace
, and the default value iscopy
. If it is set tocopy
, the meta information of the source object is used directly. If it is set toreplace
, the meta information passed in by the request is used.No x-bce-copy-source-if-none-match String If the ETag value of the source object is not equal to the ETag value provided by the user, you can perform the copy operation. Otherwise, the copy fails. No x-bce-copy-source-if-unmodified-since String If the source object is not modified after x-bce-copy-source-if-unmodified-since, the copy operation is performed. Otherwise, the copy fails. The parameter value is in the GMT format, such as Wed, 06 Apr 2016 06:34:40 GMT. No x-bce-copy-source-if-modified-since String If the source object is modified after x-bce-copy-source-if-modified-since, the copy operation is performed. Otherwise, the copy fails. The parameter value is in the GMT format, such as Wed, 06 Apr 2016 06:34:40 GMT. No x-bce-storage-class String Specifies the default storage type of the object. STANDARD_IA
represents the infrequent access,COLD
represents the cold storage, andARCHIVE
represents the archive storage. If it is not specified, it is the standard storage by default. If it is a multi-AZ bucket,MAZ_STANDARD_IA
represents the multi-AZ infrequent access. If it is not specified, it is a multi-AZMAZ_STANDARD
by default and cannot be other values.No x-bce-acl String Header supported by CannedACL, in which the user sets the permission of the object, whose value is private or public-read. No x-bce-grant-read String Header supported by CannedACL, in which the user sets the read permission of the object. It supports multiple IDs separated by commas No x-bce-grant-full-control String Header supported by CannedACL, in which the user sets the FULL_CONTROL permission of the object. It supports multiple IDs separated by commas No x-bce-server-side-encryption String Server encryption algorithm. Only AES256 is supported currently. No
Response
-
Response header field
No special header field.
-
Response parameters
Name Type Description ETag String ETagof the destination object lastModified DATE Last modification time of the destination object Considerations
- The requester must have the read permission of the source object.
- Before the signature calculation, users need to carry out the url-encode once for the content of the non-standard ASCII characters (for example, Chinese) in the x-bce-copy-source field,.
- To maintain the HTTP connection during the copy, the HTTP results of CopyObject interface can use Transfer-Encoded: Chunked encoding.
- If a server error occurs during CopyObject, the HTTP status code may return 2XX, but the copy fails. Judge the copy results according to JSON in the HTTP body.
- If the source object is of archive type, you need to restrieve the archive type before you call the CopyObject interface.
- The meta information cannot be updated for the archive object through CopyObject. You can use the replacement mode. The source and destination point to the same file.
- When you copy a soft link file, no data is copied. If you use the soft link to access this interface and the destination file of the soft link is deleted, it returns “HTTP 404: SymlinkTargetNotExist”.
Example
-
Example of standard storage request
PUT /ObjectName HTTP/1.1 Host: BucketName.bj.bcebos.com Date: Wed, 06 Apr 2016 06:34:40 GMT Authorization: AuthorizationString Content-Length: 0 Content-Type:text/plain x-bce-copy-source: /SourceBucket/SourceObject x-bce-copy-source-if-match: 3858f62230ac3c915f300c664312c11f x-bce-metadata-directive: replace
-
Example of infrequent access/cold storage request
PUT /object HTTP/1.1 Host: BucketName.bj.bcebos.com Date: Wed, 06 Apr 2016 06:34:40 GMT Authorization: AuthorizationString Content-Length: 0 Content-Type:text/plain x-bce-copy-source: /SourceBucket/SourceObject x-bce-copy-source-if-match: 3858f62230ac3c915f300c664312c11f x-bce-storage-class: STANDARD_IA
-
Response example
Copy succeeded
HTTP/1.1 200 OK x-bce-request-id: 4db2b34d-654d-4d8a-b49b-3049ca786409 Date: Wed, 06 Apr 2016 06:34:40 GMT Connection: close Server: BceBos { "lastModified":"2009-10-28T22:32:00Z", "ETag":"9b2cf535f27731c974343645a3985328" }
You need to judge the server exception according to the returned JSON.
HTTP/1.1 200 OK Date: Thu, 12 May 2016 09:14:32 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Server: BceBos x-bce-request-id: bb90cc9c-2b80-462c-87a4-095e610c9a2f Transfer-Encoding: chunked { "code":"InternalError", "message":"We encountered an internal error. Please try again.", "requestId":"52454655-5345-4420-4259-204e47494e58" }