Copying Objects

Application Scenario

You can copy objects in OBS. An object of up to 5 GB can be copied by each operation. To copy an object larger than 5 GB, use the multipart upload API. Specifically, this copy operation allows you to:

  • Create a copy for an object.
  • Rename an object by creating a copy for it and deleting the source object.
  • Change the metadata of an object. Every object has metadata which is a field-value pair. When you upload an object, you can set its metadata. After the object is uploaded, you cannot modify its metadata. The only way to modify object metadata is to create an object copy and set metadata. In the copy operation, set the target object to be the same as the source object.

Each object contains metadata, including system metadata and user-defined metadata. You can control some system metadata. When you copy an object, user-controlled system metadata and user-defined metadata are copied too. OBS resets the metadata controlled by the system. For example, when you copy an object, the OBS resets the creation date of the copied object. In the copy request, you do not need to set such value.

When copying an object, you may want to update some metadata. For example, if the source object is configured to be in Standard storage, you may want to change the storage class of the object copy to Infrequent Access. You may also want to modify some user-defined metadata of the source object. If you want to modify metadata, even only one piece of metadata, that can be configured by users (defined by users or the system), specify all the metadata that can be configured by users on the source object in the request.

If you want objects to be automatically copied to another other region, create a cross-region replication rule so that off-site disaster recovery can be ensured. For details, see Cross-Region Replication.

When versioning is disabled for a bucket, if you make a copy of objecta and save it as objectb, and an object named objectb already exists, the new objectb will overwrite the existing one. After the copying is executed successfully, only new objectb can be downloaded because old objectb has been deleted. Therefore, before copying an object, make sure that there is no object with the same name as the object copy to prevent data from being deleted mistakenly. Source object objecta does not change during the copying.

You cannot determine whether a request is executed successfully only using status_code in the header returned by HTTP. If 200 in status_code is returned, the server has received the request and starts to process the request. The body in the response shows whether the request is executed successfully. The request is executed successfully only when the body contains Etag; otherwise, the request fails to be executed.

How to Use This Function

You can use APIs, SDKs, OBS Browser+, or obsutil to copy objects.

Tool

Reference

SDKs

OBS supports software development kits (SDKs) in multiple languages. For details, see the corresponding developer guide on the SDK Overview page.

APIs

Copying Objects

OBS Browser+

-

obsutil

Copying Objects