拷贝对象

对象是存储数据的基本单元。对象由元信息(Object Meta),用户数据(Data)和文件名(Key)组成。对象由桶内部唯一的Key来标识。本文介绍如何拷贝对象。

接口定义:

// 简化接口	
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey)
// 完整接口
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest)

参数:

参数名 类型 说明
sourceBucketName String 源bucket及请求参数
sourceKey String 源对象名
destinationBucketName String 目的bucket
destinationKey String 目的对象名

代码示例:

    public void CopyObjects(String sourceBucketName, String sourceObjectKey,
                            String destBucketName, String destObjectKey,
                            OnS3ResponseListener<CopyObjectResult> listener) {
        GlobalThreadPool.getInstance().execute(() -> {
            try {
                CopyObjectResult result = sS3Client.copyObject(sourceBucketName, sourceObjectKey, destBucketName, destObjectKey);

                Handler mainHandler = new Handler(Looper.getMainLooper());
                mainHandler.post(() -> listener.onResponse(result));
            } catch (Exception e) {
                Handler mainHandler = new Handler(Looper.getMainLooper());
                mainHandler.post(() -> listener.onError());
            }
        });
    }