Baidu AI Cloud
中国站

百度智能云

Object Storage

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

    NameTypeDescriptionRequired?
    x-bce-copy-sourceStringSource object addressYes
    x-bce-copy-source-if-matchStringIf 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-directiveStringIs the meta information of the destination object is copied from the source object or passed in by the request? The valid value is copy and replace, and the default value is copy. If it is set to copy, the meta information of the source object is used directly. If it is set to replace, the meta information passed in by the request is used. No
    x-bce-copy-source-if-none-matchStringIf 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-sinceStringIf 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-sinceStringIf 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-classString Specifies the default storage type of the object. STANDARD_IA represents the infrequent access, COLD represents the cold storage, and ARCHIVE 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-AZ MAZ_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 StringServer 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

    1. The requester must have the read permission of the source object.
    2. 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,.
    3. To maintain the HTTP connection during the copy, the HTTP results of CopyObject interface can use Transfer-Encoded: Chunked encoding.
    4. 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.
    5. If the source object is of archive type, you need to restrieve the archive type before you call the CopyObject interface.
    6. 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.
    7. 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"
    }
Previous
AppendObject
Next
DeleteMultipleObjects