Updated on 2024-11-26 GMT+08:00

Copying Objects

Scenarios

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.
  • Edit object metadata.

    Each object has metadata, which is a set of name-value pairs. There is system-defined metadata and user-defined metadata. Some system-defined metadata can also be controlled by users. When you upload an object, you can set its metadata.

    • After you upload the object, you can modify its metadata using an API. For details, see Modifying Object Metadata.
    • You can also create an object copy and set the metadata. In the copy operation, set the target object to be the same as the source object.

    Both user-controlled metadata and user-defined metadata are copied. OBS automatically resets the system-controlled metadata. In the copy request, you do not need to set such metadata. For example, when you copy an object, OBS resets the creation date of the copied 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.

Prerequisites

You have the read permission for the source object and the read and write permissions for the destination bucket.

Important Notes

  • Objects cannot be copied across regions. For example, objects in a bucket in the CN North-Beijing1 region cannot be copied to a bucket in the CN North-Beijing4 region. For details about how to automatically copy objects across regions, see Cross-Region Replication.
  • An appendable object cannot be copied.
  • You can copy an object of up to 5 GB in a single operation. To copy an object larger than 5 GB, use the multipart upload API.
  • If you want to copy a large number of Deep Archive objects, you can set the storage class of the copied objects to Standard and then transition them to the Deep Archive storage class through lifecycle rules to lower the costs on PUT requests.
  • By default, an original object will be overwritten by its copy with the same name. After the copy is successful, only the new object can be downloaded. The original object will be deleted. To prevent data loss:
    • Before copying an object, ensure that there is no object with the same name as the object copy or the object with the same name is useless.
    • Enable versioning.

      If versioning is enabled, deleted or overwritten objects will be retained as historical versions. You can restore a historical version at any time.

  • OBS allows you to copy your service data stored in OBS to a specified region, but Huawei Cloud does not detect the stored data. You need to ensure the legal compliance of your use of OBS on your own. If cross-border transfer is required, ensure that your use complies with relevant laws and regulations.
  • You cannot determine whether a copy request is executed successfully only using status_code in the HTTP header. 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.

Ways to Copy Objects

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