API | 操作名 | 操作描述 |
设置对象复制(修改对象属性) | 复制文件到目标路径 | |
删除单个对象 | 在存储桶中删除指定对象 |
API | 操作名 | 操作描述 |
查询分块上传/复制 | 查询正在进行中的分块上传/复制信息 | |
初始化分块上传/复制 | 初始化分块上传/复制操作 | |
复制分块 | 将其他对象复制为一个分块 | |
查询已上传/复制块 | 查询特定分块操作中的已上传/复制的块 | |
完成分块上传/复制 | 完成整个文件的分块上传/复制 | |
终止分块上传/复制 | 终止一个分块操作并删除已上传/复制的块 |
// 初始化 TransferConfig,这里使用默认配置,如果需要定制,请参考 SDK 接口文档TransferConfig transferConfig = new TransferConfig.Builder().build();//初始化 TransferManagerTransferManager transferManager = new TransferManager(cosXmlService,transferConfig);String sourceAppid = "1250000000"; //账号 APPIDString sourceBucket = "sourcebucket-1250000000"; //源对象所在的存储桶String sourceRegion = "COS_REGION"; //源对象的存储桶所在的地域String sourceCosPath = "sourceObject"; //源对象的对象键//构造源对象属性CopyObjectRequest.CopySourceStruct copySourceStruct =new CopyObjectRequest.CopySourceStruct(sourceAppid, sourceBucket, sourceRegion, sourceCosPath);//目标桶// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";//目标对象String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键//复制对象COSXMLCopyTask cosxmlCopyTask = transferManager.copy(bucket, cosPath,copySourceStruct);//设置返回结果回调cosxmlCopyTask.setCosXmlResultListener(new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {COSXMLCopyTask.COSXMLCopyTaskResult copyResult =(COSXMLCopyTask.COSXMLCopyTaskResult) result;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest request,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});//设置任务状态回调, 可以查看任务过程cosxmlCopyTask.setTransferStateListener(new TransferStateListener() {@Overridepublic void onStateChanged(TransferState state) {// todo notify transfer state}});
final String sourceAppid = "1250000000"; //账号 appidfinal String sourceBucket = "sourcebucket-1250000000"; //"源对象所在的存储桶final String sourceRegion = "COS_REGION"; //源对象的存储桶所在的地域final String sourceKey = "sourceObject"; //源对象键//构造源对象属性CopyObjectRequest.CopySourceStruct copySource = new CopyObjectRequest.CopySourceStruct(sourceAppid, sourceBucket,sourceRegion, sourceKey);String bucket = "examplebucket-1250000000"; //目标存储桶,格式:BucketName-APPIDString key = "exampleobject"; //目标对象的对象键// copy(String bucket, String cosPath, CopyObjectRequest.CopySourceStruct copySourceStruct){COSXMLCopyTask copyTask = transferManager.copy(bucket, key, copySource);copyTask.setCosXmlResultListener(new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {try {// 复制成功后删除文件DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(sourceBucket, sourceKey);DeleteObjectResult deleteResult = cosXmlService.deleteObject(deleteObjectRequest);} catch (CosXmlClientException e) {e.printStackTrace();} catch (CosXmlServiceException e) {e.printStackTrace();}}@Overridepublic void onFail(CosXmlRequest request, CosXmlClientException exception, CosXmlServiceException serviceException) {}});
String sourceAppid = "1250000000"; //账号 APPIDString sourceBucket = "sourcebucket-1250000000"; //源对象所在的存储桶String sourceRegion = "COS_REGION"; //源对象的存储桶所在的地域String sourceCosPath = "sourceObject"; //源对象键// 构造源对象属性CopyObjectRequest.CopySourceStruct copySourceStruct =new CopyObjectRequest.CopySourceStruct(sourceAppid, sourceBucket, sourceRegion, sourceCosPath);// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, cosPath,copySourceStruct);cosXmlService.copyObjectAsync(copyObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {CopyObjectResult copyObjectResult = (CopyObjectResult) result;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String sourceAppid = "1250000000"; //账号 APPIDString sourceBucket = "sourcebucket-1250000000"; //源对象所在的存储桶String sourceRegion = "COS_REGION"; //源对象的存储桶所在的地域String sourceCosPath = "sourceObject"; //源对象键// 构造源对象属性CopyObjectRequest.CopySourceStruct copySourceStruct =new CopyObjectRequest.CopySourceStruct(sourceAppid, sourceBucket, sourceRegion, sourceCosPath);// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, cosPath,copySourceStruct);copyObjectRequest.setCopyMetaDataDirective(MetaDataDirective.REPLACED);copyObjectRequest.setXCOSMeta("x-cos-metadata-oldKey", "newValue");cosXmlService.copyObjectAsync(copyObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {CopyObjectResult copyObjectResult = (CopyObjectResult) result;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String appId = "1250000000"; //账号 APPID// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String region = "COS_REGION"; //源对象的存储桶所在的地域String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键// 构造源对象属性CopyObjectRequest.CopySourceStruct copySourceStruct =new CopyObjectRequest.CopySourceStruct(appId, bucket, region, cosPath);CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, cosPath,copySourceStruct);copyObjectRequest.setCopyMetaDataDirective(MetaDataDirective.REPLACED);// 修改元数据为新值copyObjectRequest.setXCOSMeta("x-cos-metadata-oldKey", "newValue");cosXmlService.copyObjectAsync(copyObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {CopyObjectResult copyObjectResult = (CopyObjectResult) result;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String appId = "1250000000"; //账号 APPID// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String region = "COS_REGION"; //源对象的存储桶所在的地域String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键// 构造源对象属性CopyObjectRequest.CopySourceStruct copySourceStruct =new CopyObjectRequest.CopySourceStruct(appId, bucket, region, cosPath);CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, cosPath,copySourceStruct);// 修改为低频存储copyObjectRequest.setCosStorageClass(COSStorageClass.STANDARD_IA);cosXmlService.copyObjectAsync(copyObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {CopyObjectResult copyObjectResult = (CopyObjectResult) result;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
本页内容是否解决了您的问题?