API | Operation | Description |
Copying an object (modifying object attributes) | Copies a file to a destination path. | |
Deleting an object | Deletes a specified object from a bucket. |
API | Operation | Description |
Querying multipart uploads/copy | Queries in-progress multipart uploads/copy. | |
Initializing a multipart upload/copy operation | Initializes a multipart upload/copy operation. | |
Copying a part | Copies an object as a part. | |
Querying uploaded/copied parts | Queries the uploaded/copied parts of a multipart operation. | |
Completing a multipart upload/copy | Completes the multipart upload/copy of a file. | |
Aborting a multipart upload/copy | Aborts a multipart operation and deletes the uploaded/copied parts. |
QCloudCOSXMLCopyObjectRequest* request = [[QCloudCOSXMLCopyObjectRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Source bucket containing the file; the current account needs to have access permission for the bucket, or the bucket should have public-read permission enabled.request.sourceBucket = @"sourcebucket-1250000000";// Name of the source filerequest.sourceObject = @"sourceObject";// APPID of the source filerequest.sourceAPPID = @"1250000000";// Source regionrequest.sourceRegion= @"COS_REGION";[request setFinishBlock:^(QCloudCopyObjectResult* result, NSError* error) {// You can get the information such as the ETag or custom headers in the response from outputObject.}];// Note that for cross-region replication, the region used for `transferManager` must be the region of the destination bucket[[QCloudCOSTransferMangerService defaultCOSTransferManager] CopyObject:request];// Cancel the copy// To cancel the copy operation, call `cancel`[request cancel];
let copyRequest = QCloudCOSXMLCopyObjectRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketcopyRequest.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"copyRequest.object = "exampleobject";// Source bucket containing the file; the current account needs to have access permission for the bucket, or the bucket should have public-read permission enabled.// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketcopyRequest.sourceBucket = "sourcebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"copyRequest.sourceObject = "sourceObject";// APPID of the source filecopyRequest.sourceAPPID = "1250000000";// Source regioncopyRequest.sourceRegion = "COS_REGION";copyRequest.setFinish { (copyResult, error) inif let copyResult = copyResult {// ETag of the filelet eTag = copyResult.eTag} else {print(error!);}}// Note that for cross-region replication, the region used for `transferManager` must be the region of the destination bucketQCloudCOSTransferMangerService.defaultCOSTransferManager().copyObject(copyRequest);// Cancel the copy// To cancel the copy operation, call `cancel`copyRequest.cancel();
Bucket
) and object key (ObjectKey
) to identify objects, moving an object will change the object identifier. Currently, COS’s Java SDK does not provide a standalone API to change object identifiers. However, you can still move the object with a combination of basic operations (object copy and object delete).picture.jpg
object to the “doc” directory that is in the same bucket (mybucket-1250000000
), you can copy the picture.jpg
to the “doc” directory (making the object key doc/picture.jpg
) and then delete the source object.picture.jpg
in the mybucket-1250000000
bucket to another bucket myanothorbucket-1250000000
, you can copy the object to the myanothorbucket-1250000000
bucket first and then delete the source object.QCloudCOSXMLCopyObjectRequest* request = [[QCloudCOSXMLCopyObjectRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".request.object = @"exampleobject";// Source bucket containing the file; the current account needs to have access permission for the bucket, or the bucket should have public-read permission enabled.request.sourceBucket = @"sourcebucket-1250000000";// Name of the source filerequest.sourceObject = @"sourceObject";// APPID of the source filerequest.sourceAPPID = @"1250000000";// Source regionrequest.sourceRegion= @"COS_REGION";[request setFinishBlock:^(QCloudCopyObjectResult* result, NSError* error) {// You can get the information such as the ETag or custom headers in the response from outputObjectif(!error){QCloudDeleteObjectRequest* deleteObjectRequest = [QCloudDeleteObjectRequest new];// Source bucket containing the file; the current account needs to have access permission for the bucket, or the bucket should have public-read permission enabled.deleteObjectRequest.bucket = @"sourcebucket-1250000000";// Name of the source object, which is also the full path of the object in COS. If the object is in a directory, the path should be "dir1/object1".deleteObjectRequest.object = @"sourceObject";[deleteObjectRequest setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the `HTTP` response headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] DeleteObject:deleteObjectRequest];}}];// Note that for cross-region movement, the region used for `transferManager` must be the region of the destination bucket.[[QCloudCOSTransferMangerService defaultCOSTransferManager] CopyObject:request];
let copyRequest = QCloudCOSXMLCopyObjectRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketcopyRequest.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".copyRequest.object = "exampleobject";// Source bucket containing the file; the current account needs to have access permission for the bucket, or the bucket should have public-read permission enabled.// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketcopyRequest.sourceBucket = "sourcebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".copyRequest.sourceObject = "sourceObject";// `APPID` of the source filecopyRequest.sourceAPPID = "1250000000";// Source regioncopyRequest.sourceRegion = "COS_REGION";copyRequest.setFinish { (copyResult, error) inif let copyResult = copyResult {// `ETag` of the filelet deleteObject = QCloudDeleteObjectRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketdeleteObject.bucket = "sourcebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".deleteObject.object = "sourceObject";deleteObject.finishBlock = {(result,error)inif let result = result {// result contains response headers} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteObject(deleteObject);} else {print(error!);}}// Note that for cross-region movement, the region used for `transferManager` must be the region of the destination bucket.QCloudCOSTransferMangerService.defaultCOSTransferManager().copyObject(copyRequest);
PUT Object-Copy
) is used to copy an object to a destination path.QCloudPutObjectCopyRequest* request = [[QCloudPutObjectCopyRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Indicates whether to copy metadata. Enumerated values: Copy, Replaced. Default value: Copy// If this field is specified as Copy, the user-defined metadata in the Header will be ignored and the object will be copied directly.// If it is specified as Replaced, the metadata will be modified based on the Header information. If the destination path is the same as the source path (i.e., when you want to modify the metadata), it must be specified as Replaced.request.metadataDirective = @"Copy";// Define the ACL attribute of Object. Valid values: private; public-read; default.// Default value: default (i.e., the object will inherit the bucket's permissions)// Note: If you do not need ACL for the object, please use default// or simply leave it blank, and the object will inherit the permissions of the bucket by default.request.accessControlList = @"default";// Path of the source objectrequest.objectCopySource =@"sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject";// Specify the `versionID` of the source file. This parameter is only returned for buckets whose versioning is enabled or suspendedrequest.versionID = @"objectVersion1";[request setFinishBlock:^(QCloudCopyObjectResult * _Nonnull result,NSError * _Nonnull error) {// result contains the request result.}];[[QCloudCOSXMLService defaultCOSXML] PutObjectCopy:request];
let putObjectCopy = QCloudPutObjectCopyRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketputObjectCopy.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"putObjectCopy.object = "exampleobject";// Path of the source objectputObjectCopy.objectCopySource = "sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject";// Indicates whether to copy metadata. Enumerated values: Copy, Replaced. Default value: Copy// If this field is specified as Copy, the user-defined metadata in the Header will be ignored and the object will be copied directly// If it is specified as `Replaced`, the metadata will be modified based on the header information. If the destination path is the same as the source path (i.e., when you want to modify the metadata), it must be specified as `Replaced`putObjectCopy.metadataDirective = "Copy";// Define the ACL attribute of the object. Valid values: private, public-read, default.// Default value: default (i.e., the object will inherit the bucket's permissions)// Note: If you do not need ACL for the object, please use default// or simply leave it blank, and the object will inherit the permissions of the bucket by default.putObjectCopy.accessControlList = "default";// Specify the versionID of the source file. This parameter is only returned for buckets whose versioning is enabled or suspendedputObjectCopy.versionID = "versionID";putObjectCopy.setFinish { (result, error) inif let result = result {let eTag = result.eTag} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putObjectCopy(putObjectCopy);
QCloudPutObjectCopyRequest* request = [[QCloudPutObjectCopyRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Indicates whether to copy metadata. Enumerated values: Copy, Replaced. Default value: Copy// If this field is specified as Copy, the user-defined metadata in the Header will be ignored and the object will be copied directly.// If it is specified as Replaced, the metadata will be modified based on the Header information. If the destination path is the same as the source path (i.e., when you want to modify the metadata), it must be specified as Replacedrequest.metadataDirective = @"Replaced";// Modify the metadata[request.customHeaders setValue:@"newValue" forKey:@"x-cos-meta-*"];// Storage class. For enumerated values, see **Storage Class Overview**, such as// `STANDARD_IA` and `ARCHIVE`. For the enumerated values, please see the Storage Class documentation. This header will be returned only if the storage class of the file is not `STANDARD`.// Modify the storage class[request.customHeaders setValue:@"newValue" forKey:@"x-cos-storage-class"];// Define the ACL attribute of the object. Valid values: private, public-read, default.// Default value: default (i.e., the object will inherit the bucket's permissions)// Note: If you do not need ACL for the object, please use default// or simply leave it blank, and the object will inherit the permissions of the bucket by default.// Modify the ACLrequest.accessControlList = @"private";// Path of the source objectrequest.objectCopySource =@"sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject";// Specify the versionID of the source file. This parameter is only returned for buckets whose versioning is enabled or suspendedrequest.versionID = @"objectVersion1";[request setFinishBlock:^(QCloudCopyObjectResult * _Nonnull result,NSError * _Nonnull error) {// result contains the request result.}];[[QCloudCOSXMLService defaultCOSXML] PutObjectCopy:request];
let request : QCloudPutObjectCopyRequest = QCloudPutObjectCopyRequest();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";// Indicates whether to copy metadata. Enumerated values: Copy, Replaced. Default value: Copy// If this field is specified as Copy, the user-defined metadata in the header will be ignored and the object will be copied directly// If it is specified as Replaced, the metadata will be modified based on the Header information. If the destination path is the same as the source path (i.e., when you want to modify the metadata), it must be specified as Replaced.request.metadataDirective = "Replaced";// Modify the metadatarequest.customHeaders.setValue("newValue", forKey: "x-cos-meta-*");// Storage class. For enumerated values, see **Storage Class Overview**, such as// `STANDARD_IA` and `ARCHIVE`. For the enumerated values, please see the Storage Class documentation. This header will be returned only if the storage class of the file is not `STANDARD`.// Modify the storage classrequest.customHeaders.setValue("newValue", forKey: "x-cos-storage-class");// Define the ACL attribute of the object. Valid values: private, public-read, default.// Default value: default (i.e., the object will inherit the bucket's permissions)// Note: If you do not need ACL for the object, please use default// or simply leave it blank, and the object will inherit the permissions of the bucket by default.// Modify the ACLrequest.accessControlList = "Source file ACL";// Path of the source objectrequest.objectCopySource = "sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject";// Specify the versionID of the source file. This parameter is only returned for buckets whose versioning is enabled or suspendedrequest.versionID = "versionID";request.setFinish { (result, error) inif let result = result {let eTag = result.eTag} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putObjectCopy(request);
QCloudPutObjectCopyRequest* request = [[QCloudPutObjectCopyRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Indicates whether to copy metadata. Enumerated values: Copy, Replaced. Default value: Copy// If this field is specified as Copy, the user-defined metadata in the header will be ignored and the object will be copied directly// If it is specified as Replaced, the metadata will be modified based on the Header information. If the destination path is the same as the source path (i.e., when you want to modify the metadata), it must be specified as Replacedrequest.metadataDirective = @"Replaced";// Custom object header[request.customHeaders setValue:@"newValue" forKey:@"x-cos-meta-*"];// Define the ACL attribute of the object. Valid values: private, public-read, default.// Default value: default (i.e., the object will inherit the bucket's permissions)// Note: If you do not need ACL for the object, please use default// or simply leave it blank, and the object will inherit the permissions of the bucket by default.request.accessControlList = @"default";// Path of the source objectrequest.objectCopySource =@"examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/exampleobject";[request setFinishBlock:^(QCloudCopyObjectResult * _Nonnull result,NSError * _Nonnull error) {// result contains the request result}];[[QCloudCOSXMLService defaultCOSXML] PutObjectCopy:request];
let request : QCloudPutObjectCopyRequest = QCloudPutObjectCopyRequest();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";// Indicates whether to copy metadata. Enumerated values: Copy, Replaced. Default value: Copy// If this field is specified as Copy, the user-defined metadata in the header will be ignored and the object will be copied directly// If it is specified as Replaced, the metadata will be modified based on the Header information. If the destination path is the same as the source path// (i.e., you want to modify the metadata), it must be set to `Replaced`.request.metadataDirective = "Replaced";// Custom object headerrequest.customHeaders.setValue("newValue", forKey: "x-cos-meta-*")// Define the ACL attribute of the object. Valid values: private, public-read, default.// Default value: default (i.e., the object will inherit the bucket's permissions)// Note: If you do not need ACL for the object, please use default// or simply leave it blank, and the object will inherit the permissions of the bucket by default.request.accessControlList = "default";// Path of the source objectrequest.objectCopySource ="examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/exampleobject";request.setFinish { (result, error) inif let result = result {// ETag of the destination objectlet eTag = result.eTag} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putObjectCopy(request);
QCloudPutObjectCopyRequest* request = [[QCloudPutObjectCopyRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Storage class. For enumerated values, see **Storage Class Overview**, such as// `STANDARD_IA` and `ARCHIVE`. For the enumerated values, please see the Storage Class documentation. This header will be returned only if the storage class of the file is not `STANDARD`.[request.customHeaders setValue:@"ARCHIVE" forKey:@"x-cos-storage-class"];// Path of the source objectrequest.objectCopySource =@"examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/exampleobject";// Specify the versionID of the source file. This parameter is only returned for buckets whose versioning is enabled or suspendedrequest.versionID = @"";[request setFinishBlock:^(QCloudCopyObjectResult * _Nonnull result,NSError * _Nonnull error) {// result contains the request result.}];[[QCloudCOSXMLService defaultCOSXML] PutObjectCopy:request];
let request : QCloudPutObjectCopyRequest = QCloudPutObjectCopyRequest();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";// Storage class. For enumerated values, see **Storage Class Overview**, such as// `STANDARD_IA` and `ARCHIVE`. For the enumerated values, please see the Storage Class documentation. This header will be returned only if the storage class of the file is not `STANDARD`.request.customHeaders.setValue("newValue", forKey: "x-cos-storage-class");// Path of the source objectrequest.objectCopySource ="examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/exampleobject";request.setFinish { (result, error) inif let result = result {// ETag of the destination objectlet eTag = result.eTag} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putObjectCopy(request);
Initiate Multipart Upload
and get the UploadId
.UploadId
to copy the parts with Upload Part - Copy
.Complete Multipart Upload
.UploadId
of the multipart upload, you can query the multipart copy job with List Multipart Uploads
to get the UploadId
of the corresponding file.UploadId
to list the copied parts with List Parts
.UploadId
to copy the remaining parts with Upload Part - Copy
.Complete Multipart Upload
.UploadId
of the multipart copy, you can query the multipart copy job with List Multipart Upload
to get the UploadId
.Abort Multipart Upload
.List Multipart Uploads
) is used to query in-progress multipart copies in a specified bucket, which is the same as the API for querying a multipart upload.QCloudListBucketMultipartUploadsRequest* uploads = [QCloudListBucketMultipartUploadsRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketuploads.bucket = @"examplebucket-1250000000";// Set the maximum number of parts to return. Value range: 1–1000uploads.maxUploads = 100;[uploads setFinishBlock:^(QCloudListMultipartUploadsResult* result,NSError *error) {// You can get the information on in-progress multipart uploads from result// Object in the ongoing multipart copyNSArray<QCloudListMultipartUploadContent*> *uploads = result.uploads;}];[[QCloudCOSXMLService defaultCOSXML] ListBucketMultipartUploads:uploads];
let listParts = QCloudListBucketMultipartUploadsRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketlistParts.bucket = "examplebucket-1250000000";// Set the maximum number of parts to return. Value range: 1–1000listParts.maxUploads = 100;listParts.setFinish { (result, error) inif let result = result {// List all the unfinished multipart copylet uploads = result.uploads;} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().listBucketMultipartUploads(listParts);
uploadId
, which is the same as the API for initializing a multipart upload.QCloudInitiateMultipartUploadRequest* initRequest = [QCloudInitiateMultipartUploadRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketinitRequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"initRequest.object = @"exampleobject";// This will be returned as object metadatainitRequest.cacheControl = @"cacheControl";initRequest.contentDisposition = @"contentDisposition";// Define the ACL attribute of the object. Valid values: private (default), public-read-write, public-readinitRequest.accessControlList = @"public";// Grant read permission.initRequest.grantRead = @"grantRead";// Grant full permissions to the grantee.initRequest.grantFullControl = @"grantFullControl";[initRequest setFinishBlock:^(QCloudInitiateMultipartUploadResult* outputObject,NSError *error) {// Get the uploadId of the multipart copy. This ID is required for the subsequent copy. Please save it for future use.self->uploadId = outputObject.uploadId;}];[[QCloudCOSXMLService defaultCOSXML] InitiateMultipartUpload:initRequest];
let initRequest = QCloudInitiateMultipartUploadRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketinitRequest.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"initRequest.object = "exampleobject";initRequest.setFinish { (result, error) inif let result = result {// Get the uploadId of the multipart copy. This ID is required for the subsequent copy. Please save it for future use.self.uploadId = result.uploadId;} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().initiateMultipartUpload(initRequest);
Upload Part-Copy
) is used to copy an object as a part.QCloudUploadPartCopyRequest* request = [[QCloudUploadPartCopyRequest alloc] init];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// URL path of the source file. A previous version can be specified by using the versionID subresource.request.source = @"sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject";// The Initiate Multipart Copy request returns an upload ID that uniquely identifies the copy.request.uploadID = uploadId;// Number that identifies the partrequest.partNumber = 1;[request setFinishBlock:^(QCloudCopyObjectResult* result, NSError* error) {QCloudMultipartInfo *part = [QCloudMultipartInfo new];// Get the ETag of the copied partpart.eTag = result.eTag;part.partNumber = @"1";// Save it for completing the copyingself.parts=@[part];}];[[QCloudCOSXMLService defaultCOSXML]UploadPartCopy:request];
let req = QCloudUploadPartCopyRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketreq.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"req.object = "exampleobject";// URL path of the source file. A previous version can be specified by using the versionID subresource.req.source = "sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject";// The Initiate Multipart Copy request returns an upload ID that uniquely identifies the copy.if let uploadId = self.uploadId {req.uploadID = uploadId;}// Number that identifies the partreq.partNumber = 1;req.setFinish { (result, error) inif let result = result {let mutipartInfo = QCloudMultipartInfo.init();// Get the ETag of the copied partmutipartInfo.eTag = result.eTag;mutipartInfo.partNumber = "1";// Save it for completing the copyingself.parts = [mutipartInfo];} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().uploadPartCopy(req);
List Parts
) is used to query the copied part under a specified copy, which is the same as the API for querying uploaded parts.QCloudListMultipartRequest* request = [QCloudListMultipartRequest new];// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// The Initiate Multipart Copy request returns an upload ID that uniquely identifies the copy.request.uploadId = uploadId;[request setFinishBlock:^(QCloudListPartsResult * _Nonnull result,NSError * _Nonnull error) {// Get the copied part information from result// Information on each partNSArray<QCloudMultipartUploadPart*> *parts = result.parts;}];[[QCloudCOSXMLService defaultCOSXML] ListMultipart:request];
let req = QCloudListMultipartRequest.init();// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"req.object = "exampleobject";// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketreq.bucket = "examplebucket-1250000000";// The Initiate Multipart Copy request returns an upload ID that uniquely identifies the copy.if let uploadId = self.uploadId {req.uploadId = uploadId;}req.setFinish { (result, error) inif let result = result {// All uploaded partslet parts = result.parts} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().listMultipart(req);
Complete Multipart Upload
) is used to complete the multipart copy of a file, which is the same as the API for completing a multipart upload.QCloudCompleteMultipartUploadRequest *completeRequst = [QCloudCompleteMultipartUploadRequest new];// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"completeRequst.object = @"exampleobject";// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketcompleteRequst.bucket = @"examplebucket-1250000000";// `uploadId` of the multipart copy to be queried. This ID can be obtained from `QCloudInitiateMultipartUploadResult`, i.e. the result of the multipart copy initialization request.completeRequst.uploadId = uploadId;// Copied part informationQCloudCompleteMultipartUploadInfo *partInfo = [QCloudCompleteMultipartUploadInfo new];NSMutableArray * parts = [self.parts mutableCopy];// Sort the copied parts.[parts sortUsingComparator:^NSComparisonResult(QCloudMultipartInfo* _Nonnull obj1,QCloudMultipartInfo* _Nonnull obj2) {int a = obj1.partNumber.intValue;int b = obj2.partNumber.intValue;if (a < b) {return NSOrderedAscending;} else {return NSOrderedDescending;}}];partInfo.parts = [parts copy];completeRequst.parts = partInfo;[completeRequst setFinishBlock:^(QCloudUploadObjectResult * _Nonnull result,NSError * _Nonnull error) {// Get the copy result from result}];[[QCloudCOSXMLService defaultCOSXML] CompleteMultipartUpload:completeRequst];
let complete = QCloudCompleteMultipartUploadRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketcomplete.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"complete.object = "exampleobject";// `uploadId` of the multipart copy to be queried. This ID can be obtained from// `QCloudInitiateMultipartUploadResult`, i.e., the result of the multipart copy initialization requestcomplete.uploadId = "exampleUploadId";if let uploadId = self.uploadId {complete.uploadId = uploadId;}// Copied part informationlet completeInfo = QCloudCompleteMultipartUploadInfo.init();if self.parts == nil {print ("parts that have not completed yet");return;}if self.parts != nil {completeInfo.parts = self.parts ?? [];}complete.parts = completeInfo;complete.setFinish { (result, error) in// Get the copy result from result}QCloudCOSXMLService.defaultCOSXML().completeMultipartUpload(complete);
Abort Multipart Upload
) is used to abort a multipart copy and delete the copied parts, which is the same as the API for aborting a multipart upload.QCloudAbortMultipfartUploadRequest *abortRequest = [QCloudAbortMultipfartUploadRequest new];// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"abortRequest.object = @"exampleobject";// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketabortRequest.bucket = @"examplebucket-1250000000";// uploadId of the multipart copy to be aborted// This ID can be obtained from `QCloudInitiateMultipartUploadResult`, i.e. the result of the multipart copy initialization requestabortRequest.uploadId = @"exampleUploadId";[abortRequest setFinishBlock:^(id outputObject, NSError *error) {// You can get the information such as the ETag or custom headers in the response from outputObjectNSDictionary * result = (NSDictionary *)outputObject;}];[[QCloudCOSXMLService defaultCOSXML]AbortMultipfartUpload:abortRequest];
let abort = QCloudAbortMultipfartUploadRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketabort.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"abort.object = "exampleobject";// uploadId of the multipart copy to be queried. This ID can be obtained from// `QCloudInitiateMultipartUploadResult`, i.e., the result of the multipart copy initialization requestabort.uploadId = self.uploadId!;abort.finishBlock = {(result,error)inif let result = result {// You can get the header information returned by the server from result} else {print(error!)}}QCloudCOSXMLService.defaultCOSXML().abortMultipfartUpload(abort);
Apakah halaman ini membantu?