You can copy an object from a source bucket to another bucket that resides in the same region without modifying the content of the object.

Limits

  • Objects cannot be copied between buckets that reside in different regions. For example, an object cannot be copied from a bucket in the China (Hangzhou) region to a bucket in the China (Shanghai) region.
  • Objects generated by calling the AppendObject operation cannot be copied.

Usage notes

  • You must have the read permissions on the source object and the read and write permissions on the destination bucket. Otherwise, the copy operation may fail.
  • The source bucket and the destination bucket must have no retention policies configured. Otherwise, the error message The object you specified is immutable. is returned.
  • By default, when you copy an object that has the same name as an existing object in the destination bucket, the copied object overwrites the object in the destination bucket. You can use the following methods to protect your objects from being unexpectedly overwritten:
    • Enable versioning

      If versioning is enabled for a bucket, deleted and overwritten objects in the bucket are saved as previous versions. You can recover an object to a previous version at any time. For more information, see Overview.

    • Include a parameter in the copy request header

      Include the x-oss-forbid-overwrite parameter in the copy request header and set the parameter to true. This way, when you attempt to copy an object that has the same name as an existing object in the destination bucket, the object cannot be copied. Object Storage Service (OSS) returns the FileAlreadyExists error.

Use ossbrowser

If you use ossbrowser to copy objects, the objects must be smaller than 5 GB in size. For more information about how to use ossbrowser to copy objects, see Use ossbrowser.

Use OSS SDKs

The following code provides examples on how to call the CopyObject operation to copy an object smaller than 1 GB in size by using OSS SDKs for common programming languages: For more information about how to copy objects smaller than 1 GB in size by using OSS SDKs for other programming languages, and for information about how to call the UploadPartCopy operation to copy objects larger than 1 GB in size, see Overview.

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        // In this example, the endpoint of the China (Hangzhou) region is used. Specify the actual endpoint. 
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to access OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
        String accessKeyId = "yourAccessKeyId";
        String accessKeySecret = "yourAccessKeySecret";
        // Specify the name of the source bucket. 
        String sourceBucketName = "srcexamplebucket";
        // Specify the full path of the source object. The full path of the object cannot contain the bucket name. 
        String sourceKey = "srcexampleobject.txt";
        // Specify the name of the destination bucket. The destination bucket must be in the same region as the source bucket. 
        String destinationBucketName = "desexamplebucket";
        // Specify the full path of the destination object. The full path of the object cannot contain the bucket name. 
        String destinationKey = "desexampleobject.txt";

        // Create an OSSClient instance. 
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        try {
            // Create a CopyObjectRequest object. 
            CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey);

            // Configure the metadata of the destination object. 
            ObjectMetadata meta = new ObjectMetadata();
            meta.setContentType("text/txt");
            // Specify whether the CopyObject operation overwrites the object with the same name. In this example, this parameter is set to true, which indicates that the object with the same name cannot be overwritten. 
            // meta.setHeader("x-oss-forbid-overwrite", "true");
            // Specify the path of the source object. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_SOURCE, "/examplebucket/recode-test.txt");
            // If the ETag value of the source object is the same as the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_SOURCE_IF_MATCH, "5B3C1A2E053D763E1B002CC607C5****");
            // If the ETag value of the source object is different from the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_SOURCE_IF_NONE_MATCH, "5B3C1A2E053D763E1B002CC607C5****");
            // If the time that is specified in the request is later than or equal to the actual modified time of the source object, OSS copies the object and returns 200 OK. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_SOURCE_IF_UNMODIFIED_SINCE, "2021-12-09T07:01:56.000Z");
            // If the source object is modified after the time that is specified in the request, OSS copies the object. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_SOURCE_IF_MODIFIED_SINCE, "2021-12-09T07:01:56.000Z");
            // Specify the method that is used to configure the metadata of the destination object. In this example, the method is set to COPY, which indicates that the metadata of the source object is copied to the destination object. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_METADATA_DIRECTIVE, "COPY");
            // Specify the server-side encryption algorithm that is used to encrypt the destination object when OSS creates the object. 
            // meta.setHeader(OSSHeaders.OSS_SERVER_SIDE_ENCRYPTION, ObjectMetadata.KMS_SERVER_SIDE_ENCRYPTION);
            // Specify the customer master key (CMK) that is managed by Key Management Service (KMS). This parameter takes effect only when you set x-oss-server-side-encryption to KMS. 
            // meta.setHeader(OSSHeaders.OSS_SERVER_SIDE_ENCRYPTION_KEY_ID, "9468da86-3509-4f8d-a61e-6eab1eac****");
            // Specify the access control list (ACL) of the destination object. In this example, the ACL is set to private, which indicates that only the owner of the object and authorized users have read and write permissions on the object. 
            // meta.setHeader(OSSHeaders.OSS_OBJECT_ACL, CannedAccessControlList.Private);
            // Specify the storage class of the destination object. In this example, the storage class is set to Standard. 
            // meta.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard);
            // Specify tags for the destination object. You can specify multiple tags for the destination object at the same time. 
            // meta.setHeader(OSSHeaders.OSS_TAGGING, "a:1");
            // Specify the method that is used to configure tags for the destination object. In this example, the method is set to COPY, which indicates that the tags of the source object are copied to the destination object. 
            // meta.setHeader(OSSHeaders.COPY_OBJECT_TAGGING_DIRECTIVE, "COPY");
            copyObjectRequest.setNewObjectMetadata(meta);

            // Copy the object. 
            CopyObjectResult result = ossClient.copyObject(copyObjectRequest);
            System.out.println("ETag: " + result.getETag() + " LastModified: " + result.getLastModified());
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}                 
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\OssClient;
use OSS\Core\OssException;

// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
$accessKeyId = "yourAccessKeyId";
$accessKeySecret = "yourAccessKeySecret";
// In this example, the endpoint of the China (Hangzhou) region is used. Specify the endpoint based on your business requirements. 
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the source bucket. Example: srcexamplebucket. 
$from_bucket = "srcexamplebucket";
// Specify the full path of the source object. The full path of the object cannot contain the bucket name. Example: srcdir/exampleobject.txt. 
$from_object = "srcdir/exampleobject.txt";
// Specify the name of the destination bucket. The destination bucket must be in the same region as the source bucket. Example: destexamplebucket. 
// If you copy an object within a bucket, make sure that you specify the same bucket name for the source and destination buckets. 
$to_bucket = "destexamplebucket";
// Specify the full path of the destination object. The full path of the object cannot contain the bucket name. Example: destdir/exampleobject.txt. 
$to_object = "destdir/exampleobject.txt";

$options = array(
    'headers'=>array(
      // Specify whether the CopyObject operation overwrites the object with the same name. In this example, this parameter is set to true, which indicates that the object with the same name cannot be overwritten. 
      // 'x-oss-forbid-overwrite' => 'true',
      // If the ETag value of the source object is the same as the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
      // 'x-oss-copy-source-if-match' => '5B3C1A2E053D763E1B002CC****',
      // If the ETag value of the source object is different from the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
      // 'x-oss-copy-source-if-none-match' => '5B3C1A2E053D763E1B002CC****',
      // If the time that is specified in the request is later than or equal to the actual modified time of the source object, OSS copies the object and returns 200 OK. 
      // 'x-oss-copy-source-if-unmodified-since' => gmdate('2021-12-09T07:01:56.000Z'),
      // If the time that is specified in the request is earlier than the actual modified time of the source object, OSS copies the object and returns 200 OK. 
      // 'x-oss-copy-source-if-modified-since' => gmdate('2021-12-09T07:01:56.000Z'),
      // Specify the method that is used to configure the metadata of the destination object. In this example, the method is set to COPY, which indicates that the metadata of the source object is copied to the destination object. 
      // 'x-oss-metadata-directive' => 'COPY',
      // Specify the server-side encryption algorithm that is used to encrypt the destination object when OSS creates the object. 
      // 'x-oss-server-side-encryption' => 'KMS',
      // Specify the CMK that is managed by KMS. This parameter takes effect only when you set x-oss-server-side-encryption to KMS. 
      // 'x-oss-server-side-encryption-key-id' => '9468da86-3509-4f8d-a61e-6eab****',
      // Specify the access control list (ACL) of the destination object when OSS creates the object. In this example, the ACL is set to private, which indicates that only the owner of the object and authorized users have read and write permissions on the object. 
      // 'x-oss-object-acl' => 'private',
      // Specify the storage class of the destination object. In this example, the storage class is set to Standard. 
      // 'x-oss-storage-class' => 'Standard',
      // Specify tags for the destination object. You can specify multiple tags for the destination object at the same time. 
      // 'x-oss-tagging' => 'k1=v1&k2=v2&k3=v3',
      // Specify the method that is used to configure tags for the destination object. In this example, the method is set to COPY, which indicates that the tags of the source object are copied to the destination object. 
      // 'x-oss-tagging-directive' => 'COPY',
    ),
);

try{
    $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);

    $ossClient->copyObject($from_bucket, $from_object, $to_bucket, $to_object);
} catch(OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");            
const OSS = require('ali-oss');
const client = new OSS({

  // Set yourRegion to the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access Object Storage Service (OSS) because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Specify the bucket name. Example: examplebucket. 
  bucket: 'examplebucket',
  // Specify whether to enable HTTPS. If you set secure to true, HTTPS is enabled. 
  // secure: true
})
// Copy the objects within the same bucket. 
// Specify the full paths of the source object and the destination object. The full paths of the objects cannot contain the bucket name. 
client.copy('destexampleobject.txt', 'srcexampleobject.txt',
// Specify HTTP headers and metadata for the destination object. 
//{
    // Configure the headers parameter to specify HTTP headers for the destination object. If you do not configure the headers parameter, the HTTP headers of the destination object are the same as the HTTP headers of the source object. The HTTP headers of the source object are copied. 
    // headers:{
        //'Cache-Control': 'no-cache',        
        // If the ETag value of the source object is the same as the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
        //'if-match': '5B3C1A2E053D763E1B002CC607C5****',
        // If the ETag value of the source object is different from the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
        //'if-none-match': '5B3C1A2E053D763E1B002CC607C5****', 
        // If the time that is specified in the request is earlier than the time when the object is modified, OSS copies the object and returns 200 OK. 
        //'if-modified-since': '2021-12-09T07:01:56.000Z', 
        // If the time that is specified in the request is later than the time when the object is modified, OSS copies the object and returns 200 OK. 
        //'if-unmodified-since': '2021-12-09T07:01:56.000Z', 
        // Specify the access control list (ACL) of the destination object. In this example, the ACL is set to private, which indicates that only the object owner and authorized users have read and write permissions on the object. 
        //'x-oss-object-acl': 'private', 
        // Specify the tag for the destination object. You can specify multiple tags for the destination object at the same time. 
        //'x-oss-tagging': 'Tag1=1&Tag2=2',
        // Specify whether the CopyObject operation overwrites the object with the same name. If you set x-oss-forbid-overwrite to true, the CopyObject operation cannot overwrite the object with the same name. 
        //'x-oss-forbid-overwrite': 'true', 
    //},
    // Configure the meta parameter to specify metadata for the destination object. If you do not configure the meta parameter, the metadata of the destination object is the same as the metadata of the source object. The metadata of the source object is copied. 
    //meta:{
        // location: 'hangzhou',
        // year: 2015,
        // people: 'mary'
    //}
//}
).then((res) => {
    console.log(res);
}).catch(e => {
  console.log(e);
})
# -*- coding: utf-8 -*-
import oss2

# Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access Object Storage Service (OSS) because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console. 
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Specify the name of the source bucket. Example: srcexamplebucket. 
src_bucket_name = 'srcexamplebucket'
# Specify the name of the destination bucket, which is located in the same region as the source bucket. Example: destexamplebucket. 
# If you copy an object within a bucket, make sure that you specify the same bucket name for the source and destination buckets. 
dest_bucket_name = 'destexamplebucket'
# Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set yourEndpoint to https://oss-cn-hangzhou.aliyuncs.com. 
bucket = oss2.Bucket(auth, 'yourEndpoint', dest_bucket_name)

# Specify the full path of the source object. The full path of the object cannot contain the bucket name. Example: srcexampleobject.txt. 
src_object_name = 'srcexampleobject.txt'
# Specify the full path of the destination object. The full path of the object cannot contain the bucket name. Example: destexampleobject.txt. 
dest_object_name = 'destexampleobject.txt'

# headers = dict()
# Specify whether the CopyObject operation overwrites the object with the same name. In this example, this parameter is set to true, which indicates that the object with the same name cannot be overwritten. 
# headers['x-oss-forbid-overwrite'] = 'true'
# Specify the path of the source object. 
# headers[OSS_COPY_OBJECT_SOURCE] = '/example-bucket-by-util/recode-test.txt'
# If the ETag value of the source object is the same as the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
# headers['x-oss-copy-source-if-match'] = '5B3C1A2E053D763E1B002CC607C5****'
# If the ETag value of the source object is different from the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
# headers['x-oss-copy-source-if-none-match'] = '5B3C1A2E053D763E1B002CC607C5****'
# If the time that is specified in the request is equal to or later than the actual modified time of the object, OSS copies the object and returns 200 OK. 
# headers['x-oss-copy-source-if-unmodified-since'] = '2021-12-09T07:01:56.000Z'
# If the source object is modified after the time that is specified in the request, OSS copies the object. 
# headers['x-oss-copy-source-if-modified-since'] = '2021-12-09T07:01:56.000Z'
# Specify the method that is used to configure the metadata of the destination object. If you set the method to COPY, the metadata of the source object is copied to the destination object. 
# headers[OSS_METADATA_DIRECTIVE] = 'COPY'
# Specify the server-side encryption algorithm that is used to encrypt the destination object when OSS creates the destination object. 
# headers[OSS_SERVER_SIDE_ENCRYPTION] = 'KMS'
# Specify the customer master key (CMK) that is managed by Key Management Service (KMS). This parameter takes effect only when x-oss-server-side-encryption is set to KMS. 
# headers['x-oss-server-side-encryption-key-id'] = '9468da86-3509-4f8d-a61e-6eab1eac****'
# Specify the access control list (ACL) of the destination object. In this example, this parameter is set to OBJECT_ACL_PRIVATE, which indicates that only the object owner and authorized users have read and write permissions on the object. 
# headers[OSS_OBJECT_ACL] = oss2.OBJECT_ACL_PRIVATE
# Specify the storage class of the destination object. In this example, this parameter is set to BUCKET_STORAGE_CLASS_STANDARD, which indicates Standard. 
# headers['x-oss-storage-class'] = oss2.BUCKET_STORAGE_CLASS_STANDARD
# Specify the tag for the destination object. You can specify multiple tags for the destination object at the same time. 
# headers[OSS_OBJECT_TAGGING] = 'k1=v1&k2=v2&k3=v3'
# Specify the method that is used to configure the tag of the destination object. If you set the method to COPY, the tags of the source object are copied to the destination object. 
# headers[OSS_OBJECT_TAGGING_COPY_DIRECTIVE] = 'COPY'
# result = bucket.copy_object(src_bucket_name, src_object_name, dest_object_name, headers=headers)

# Copy the object from the source bucket to the destination bucket. 
result = bucket.copy_object(src_bucket_name, src_object_name, dest_object_name)

# View the HTTP status code in the returned results. If the HTTP status code 200 is returned, the execution succeeds. 
print('result.status:', result.status)
using Aliyun.OSS;
using Aliyun.OSS.Common;

// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
var endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access Object Storage Service (OSS) because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
var accessKeyId = "yourAccessKeyId";
var accessKeySecret = "yourAccessKeySecret";
// Specify the name of the source bucket. Example: srcexamplebucket. 
var sourceBucket = "srcexamplebucket";
// Specify the full path of the source object. The full path cannot contain the bucket name. Example: srcdir/scrobject.txt. 
var sourceObject = "srcdir/scrobject.txt";
// Specify the name of the destination bucket. The destination bucket must be located in the same region as the source bucket. Example: destbucket. 
var targetBucket = "destbucket";
// Specify the full path of the destination object. The full path cannot contain the bucket name. Example: destdir/destobject.txt. 
var targetObject = "destdir/destobject.txt";

// Create an OssClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
    var metadata = new ObjectMetadata();
    metadata.AddHeader("mk1", "mv1");
    metadata.AddHeader("mk2", "mv2");
    var req = new CopyObjectRequest(sourceBucket, sourceObject, targetBucket, targetObject)
    {
        // If the value of NewObjectMetadata is null, the COPY mode is used and the metadata of the source object is copied to the destination object. If the value of NewObjectMetadata is not null, the REPLACE mode is used and the metadata of the destination object is overwritten by the metadata specified in the request. 
        NewObjectMetadata = metadata 
    };
    // Copy the object. 
    client.CopyObject(req);
    Console.WriteLine("Copy object succeeded");
}
catch (OssException ex)
{
    Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID: {2} \tHostID: {3}",
        ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
}
catch (Exception ex)
{
    Console.WriteLine("Failed with error info: {0}", ex.Message);
}
// Specify the name of the source bucket. 
String srcBucketName = "srcbucket";
// Specify the full path of the object in the source bucket. 
String srcObjectKey = "dir1/srcobject.txt";
// Specify the name of the destination bucket. The destination bucket must be in the same region as the source bucket. 
String destBucketName = "destbucket";
// Specify the full path of the object in the destination bucket. 
String destObjectKey = "dir2/destobject.txt";
// Construct a request to copy the object. 
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(srcBucketName, srcObjectKey, destBucketName, destObjectKey);

// ObjectMetadata objectMetadata = new ObjectMetadata();
// Set the access control list (ACL) of the object. In this example, this parameter is set to private. 
// objectMetadata.setHeader("x-oss-object-acl", "private");
// Specify the storage class of the object. In this example, this parameter is set to Standard. 
// objectMetadata.setHeader("x-oss-storage-class", "Standard");
// Specify whether the CopyObject operation overwrites the object with the same name. If this parameter is set to true, the object with the same name cannot be overwritten. 
// objectMetadata.setHeader("x-oss-forbid-overwrite", "true");
// If the ETag value of the source object is equal to the ETag value that is specified in the request, the copy operation is performed. 
// objectMetadata.setHeader("x-oss-copy-source-if-match", "5B3C1A2E053D763E1B002CC607C5****");
// Specify the path of the source object. 
// objectMetadata.setHeader("x-oss-copy-source", "/examplebucket/recode-test.txt");
// If the ETag value of the source object is different from the ETag value that is specified in the request, the copy operation is performed. 
// objectMetadata.setHeader("x-oss-copy-source-if-none-match", "5B3C1A2E053D763E1B002CC607C5****");
// If the time that is specified in the request is equal to or later than the actual modified time of the source object, the copy operation is performed. 
// objectMetadata.setHeader("x-oss-copy-source-if-unmodified-since", "2021-12-09T07:01:56.000Z");
// If the source object is modified after the time that is specified in the request, the copy operation is performed. 
// objectMetadata.setHeader("x-oss-copy-source-if-modified-since", "2021-12-09T07:01:56.000Z");
// Specify the method that is used to configure the metadata of the destination object. If you set the method to COPY, the metadata of the source object is copied to the destination object. 
// objectMetadata.setHeader("x-oss-metadata-directive", "COPY");
// Specify the server-side encryption algorithm that is used to encrypt the destination object when OSS creates the destination object. 
// objectMetadata.setHeader("x-oss-server-side-encryption", "SSE-KMS");
// Specify the customer master key (CMK) that is managed by Key Management Service (KMS). This parameter takes effect only when x-oss-server-side-encryption is set to KMS. 
// objectMetadata.setHeader("x-oss-server-side-encryption-key-id", "9468da86-3509-4f8d-a61e-6eab1eac****");
// Specify the tag for the destination object. You can specify multiple tags at the same time. 
// objectMetadata.setHeader("x-oss-tagging", "a:1");
// Specify the method that is used to configure the tags for the destination object. If you set the method to COPY, the tags of the source object are copied to the destination object. 
// objectMetadata.setHeader("x-oss-tagging-directive", "COPY");

// Copy the object in asynchronous mode. 
OSSAsyncTask copyTask = oss.asyncCopyObject(copyObjectRequest, new OSSCompletedCallback<CopyObjectRequest, CopyObjectResult>() {
    @Override
    public void onSuccess(CopyObjectRequest request, CopyObjectResult result) {
        Log.d("copyObject", "copy success!");
    }

    @Override
    public void onFailure(CopyObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
        // Handle request exceptions. 
        if (clientExcepion != null) {
            // Handle client-side exceptions such as network errors. 
            clientExcepion.printStackTrace();
        }
        if (serviceException != null) {
            // Handle server-side exceptions. 
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});
package main

import (
    "fmt"
    "github.com/aliyun/aliyun-oss-go-sdk/oss"
    "os"
    "time"
)

func main() {
    // Create an OSSClient instance. 
    // Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set yourEndpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify the endpoint based on your business requirements. 
    // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access Object Storage Service (OSS) because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console. 
    client, err := oss.New("yourEndpoint", "yourAccessKeyId", "yourAccessKeySecret")
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
    // Specify the name of the bucket. Example: examplebucket. 
    bucketName := "examplebucket"
    // Specify the full path of the source object. Example: srcdir/srcobject.jpg. 
    objectName := "srcdir/srcobject.jpg"
    // Specify the full path of the destination object. Example: destdir/destobject.jpg. 
    destObjectName := "destdir/destobject.jpg"

    // Obtain the bucket. 
    bucket, err := client.Bucket(bucketName)
    if err != nil {
        fmt.Println("Error:", err)

        os.Exit(-1)
    }

    // Specify metadata for the destination object. 
    expires := time.Date(2049, time.January, 10, 23, 0, 0, 0, time.UTC)
    tag1 := oss.Tag{
        Key:   "a",
        Value: "1",
    }

    taggingInfo := oss.Tagging{
        Tags: []oss.Tag{tag1},
    }

    options := []oss.Option{
        oss.MetadataDirective(oss.MetaReplace),
        oss.Expires(expires),
        oss.SetTagging(taggingInfo),
        // Specify that the tags of the source object are copied to the destination object. 
        // oss.TaggingDirective(oss.TaggingCopy),
        // Set the access control list (ACL) of the destination object to private when OSS creates the destination object.     
        // oss.ObjectACL(oss.ACLPrivate),
        // Specify the customer master key (CMK) that is managed by Key Management Service (KMS). This parameter takes effect only when x-oss-server-side-encryption is set to KMS. 
        //oss.ServerSideEncryptionKeyID("9468da86-3509-4f8d-a61e-6eab1eac****"),
        // Specify the server-side encryption algorithm that is used to encrypt the destination object when OSS creates the destination object. 
        // oss.ServerSideEncryption("AES256"),
        // Specify that the metadata of the source object is copied to the destination object. 
        //oss.MetadataDirective(oss.MetaCopy),
        // Specify whether the CopyObject operation overwrites the object with the same name. In this example, this parameter is set to true, which indicates that the object with the same name cannot be overwritten. 
        // oss.ForbidOverWrite(true),
        // If the ETag value of the source object is the same as the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
        //oss.CopySourceIfMatch("5B3C1A2E053D763E1B002CC607C5****"),
        // If the ETag value of the source object is different from the ETag value that is specified in the request, OSS copies the object and returns 200 OK. 
        //oss.CopySourceIfNoneMatch("5B3C1A2E053D763E1B002CC607C5****"),
        // If the time that is specified in the request is earlier than the modified time of the object, OSS copies the object and returns 200 OK. 
        //oss.CopySourceIfModifiedSince(2021-12-09T07:01:56.000Z),
        // If the time that is specified in the request is the same as or later than the modified time of the object, OSS copies the object and returns 200 OK. 
        //oss.CopySourceIfUnmodifiedSince(2021-12-09T07:01:56.000Z),
        // Specify the storage class of the destination object. In this example, this parameter is set to Standard. 
        //oss.StorageClass("Standard"),
        }

    // Specify that the metadata of the source object is overwritten by the metadata that is specified in the request. 
    _, err = bucket.CopyObject(objectName, destObjectName, options...)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
}
OSSCopyObjectRequest * copy = [OSSCopyObjectRequest new];
// Specify the name of the source bucket. 
copy.sourceBucketName = @"sourcebucket";
// Specify the full path of the object in the source bucket. 
copy.sourceObjectKey = @"dir1/srcobject.txt";
// Specify the name of the destination bucket. 
copy.bucketName = @"destbucket";
// Specify the full path of the object in the destination bucket. 
copy.objectKey = @"dir2/destobject.txt";
NSMutableDictionary *objectMeta = [NSMutableDictionary dictionary];
// Specify the access control list (ACL) of the destination object. In this example, the ACL of the destination object is set to private. 
[objectMeta setValue:@"x-oss-object-acl" forKey:@"public-read"];
// Specify the storage class of the destination object. In this example, the storage class of the destination object is set to Standard. 
[objectMeta setValue:@"x-oss-storage-class" forKey:@"Standard"];
// Specify whether to overwrite the object with the same name. By default, if x-oss-forbid-overwrite is not specified, existing objects are overwritten by the objects with the same names. 
// If x-oss-forbid-overwrite is set to false, existing objects are overwritten by the objects with the same names. If x-oss-forbid-overwrite is set to true, existing objects are not overwritten by the objects with the same names. If an existing object has the same name as the copied object, an error is reported. 
[objectMeta setValue:@"x-oss-forbid-overwrite" forKey:@"true"];
// If the ETag value of the source object is the same as the ETag value that you specified in the request, the object is copied. 
[objectMeta setValue:@"x-oss-copy-source-if-match" forKey:@"5B3C1A2E053D763E1B002CC607C5****"];
// If the ETag value of the source object is different from the ETag value that you specified in the request, the object is copied. 
[objectMeta setValue:@"x-oss-copy-source-if-none-match" forKey:@"5B3C1A2E053D763E1B002CC607C5****"];
// If the object is modified at 07:01:56.000, December 09, 2021 or earlier in UTC, the object is copied. 
[objectMeta setValue:@"x-oss-copy-source-if-unmodified-since" forKey:@"2021-12-09T07:01:56.000Z"];
// If the object is modified after 07:01:56.000, December 15, 2021 in UTC, the object is copied. 
[objectMeta setValue:@"x-oss-copy-source-if-modified-since" forKey:@"2021-12-15T07:01:56.000Z"];
// Copy the metadata of the source object to the destination object. 
[objectMeta setValue:@"x-oss-metadata-directive" forKey:@"COPY"];
// Copy the tags of the source object to the destination object. 
[objectMeta setValue:@"x-oss-tagging-directive" forKey:@"Copy"];
// Specify the server-side encryption algorithm that is used to encrypt the destination object when OSS creates the destination object. 
[objectMeta setValue:@"x-oss-server-side-encryption" forKey:@"KMS"];
// Specify the customer master key (CMK) that is managed by Key Management Service (KMS). This parameter takes effect only when you set x-oss-server-side-encryption to KMS. 
[objectMeta setValue:@"x-oss-server-side-encryption-key-id" forKey:@"9468da86-3509-4f8d-a61e-6eab1eac****"];
copy.objectMeta = objectMeta;


OSSTask * task = [client copyObject:copy];
[task continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"copy object success!");
    } else {
        NSLog(@"copy object failed, error: %@" , task.error);
    }
    return nil;
}];
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
    /* Initialize the information about the account that is used to access Object Storage Service (OSS). */
    /* Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. */
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    /* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
    std::string Endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
    /* Specify the name of the source bucket. Example: srcexamplebucket. */
    std::string SourceBucketName = "srcexamplebucket";
    /* Specify the name of the destination bucket. The destination bucket must be located in the same region as the source bucket. Example: destbucket. */
    std::string CopyBucketName = "destbucket";
    /* Specify the full path of the source object. The full path cannot contain the bucket name. Example: srcdir/scrobject.txt. */
    std::string SourceObjectName = "srcdir/scrobject.txt";
    /* Specify the full path of the destination object. The full path cannot contain the bucket name. Example: destdir/destobject.txt. */
    std::string CopyObjectName = "destdir/destobject.txt";

    /* Initialize resources such as networks. */
    InitializeSdk();

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

    CopyObjectRequest request(CopyBucketName, CopyObjectName);
    request.setCopySource(SourceBucketName, SourceObjectName);

    /* Copy the object. */
    auto outcome = client.CopyObject(request);

    if (!outcome.isSuccess()) {
        /* Handle exceptions. */
        std::cout << "CopyObject fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        ShutdownSdk();
        return -1;
    }

    /* Release resources such as networks. */
    ShutdownSdk();
    return 0;
}
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  # Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

# Specify the bucket name. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')

# Copy the metadata of the source object to the destination object. 
bucket.copy_object(
  'my-object', 'copy-object',
  :meta_directive => Aliyun::OSS::MetaDirective::COPY)

# Use the specified metadata as the metadata of the destination object. 
bucket.copy_object(
  'my-object', 'copy-object',
  :metas => {'year' => '2017'},
  :meta_directive => Aliyun::OSS::MetaDirective::REPLACE)            

Use ossutil

For more information about how to copy objects by using ossutil, see Copy objects.

Use the RESTful API

If your business requires a high level of customization, you can directly call RESTful APIs. To directly call an API, you must include the signature calculation in your code. For more information, see CopyObject.