You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Copy Object
Standard Copy (Java SDK)
Copy page
Download PDF
Standard Copy (Java SDK)
When the object is smaller than 5 GiB, you can use the copyObject interface of the TOS Java SDK to perform a standard copy.​
Notes​
  • Copying files between buckets across regions is not supported.​
  • When copying an object, the account must have read permission for the source object and write permission for the destination bucket.​
  • When copying an object, you can either retain all metadata (the default option) or specify new metadata. However, the ACL was not retained; instead, it was set to private.​
Sample Code​
The following code demonstrates how to copy the srcObjectKey object from the srcBucketName bucket to the bucketName bucket, and set the object name as objectKey.​
​
import com.volcengine.tos.TOSV2;​
import com.volcengine.tos.TOSV2ClientBuilder;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.object.CopyObjectV2Input;​
import com.volcengine.tos.model.object.CopyObjectV2Output;​
​
public class CopyObjectExample {​
public static void main(String[] args) {​
String endpoint = "your endpoint";​
String region = "your region";​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY");​
​
String srcBucketName = "src-bucket-example";​
String srcObjectKey = "src_example_dir/example_object.txt";​
String bucketName = "bucket-example";​
String objectKey = "dst_example_dir/example_object.txt";​
​
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try{​
CopyObjectV2Input input = new CopyObjectV2Input().setBucket(bucketName).setKey(objectKey)​
.setSrcBucket(srcBucketName).setSrcKey(srcObjectKey);​
CopyObjectV2Output output = tos.copyObject(input);​
System.out.println("copyObject succeed, object's etag is " + output.getEtag());​
System.out.println("copyObject succeed, object's crc64 is " + output.getHashCrc64ecma());​
} catch (TosClientException e) {​
System.out.println("copyObject failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
System.out.println("copyObject failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
System.out.println("copyObject failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Related documentation​
For API documentation on standard copy operations, see CopyObject.​
Last updated: 2025.09.22 11:34:17