API | Operation | Description |
Uploading an object | Uploads an object to a bucket. |
API | Operation | Description |
Querying multipart uploads | Queries in-progress multipart uploads. | |
Initializing a multipart upload operation | Initializes a multipart upload operation. | |
Uploading parts | Uploads an object in multiple parts. | |
Querying uploaded parts | Queries the uploaded parts of a multipart upload. | |
Completing a multipart upload | Completes the multipart upload of a file. | |
Aborting a multipart upload | Aborts a multipart upload and deletes the uploaded parts. |
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];/** Path of the local file. Ensure that the URL starts with "file://" in the following format:1. [NSURL URLWithString:@"file:////var/mobile/Containers/Data/Application/DBPF7490-D5U8-4ABF-A0AF-CC49D6A60AEB/Documents/exampleobject"]2. [NSURL fileURLWithPath:@"/var/mobile/Containers/Data/Application/DBPF7490-D5U8-4ABF-A0AF-CC49D6A60AEB/Documents/exampleobject"]*/NSURL* url = [NSURL fileURLWithPath:@"file URL"];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = @"exampleobject";// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = url;// Monitor the upload progress[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file}];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * fileUrl = result.location;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[put setInitMultipleUploadFinishBlock:^(QCloudInitiateMultipartUploadResult *multipleUploadInitResult,QCloudCOSXMLUploadObjectResumeData resumeData) {// This block will be called back after the Initiate Multipart Upload operation is complete so you can get resumeData and the uploadId.NSString* uploadId = multipleUploadInitResult.uploadId;}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "exampleobject";// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = NSURL.fileURL(withPath: "Local File Path") as AnyObject;// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// ETag of the filelet eTag = result.eTag// File download linklet location = result.location;// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// Monitor the upload progressput.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file};// Set the upload parametersput.initMultipleUploadFinishBlock = {(multipleUploadInitResult, resumeData) in// This block will be called back after the Initiate Multipart Upload operation is complete so you can get resumeData and the uploadId.if let multipleUploadInitResult = multipleUploadInitResult {let uploadId = multipleUploadInitResult.uploadId}}QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = @"exampleobject";// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// Monitor the upload progress[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent Number of new bytes sent// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Target number of bytes expected to send}];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * fileUrl = result.location;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "exampleobject";// Content of the object to uploadlet dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// ETag of the filelet eTag = result.eTag// File download linklet location = result.location;// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// Monitor the upload progressput.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent Number of new bytes sent// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Target number of bytes expected to send};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
NSError *error;NSData *resmeData = [put cancelByProductingResumeData:&error];
QCloudCOSXMLUploadObjectRequest *resumeRequest = [QCloudCOSXMLUploadObjectRequest requestWithRequestData:resmeData];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:resumeRequest];
// Abort the upload.[put abort:^(id outputObject, NSError *error) {}];
var error : NSError?;var uploadResumeData:Data = put.cancel(byProductingResumeData:&error) as Data;
var resumeRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>.init(request: uploadResumeData);QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(resumeRequest);
// Abort the upload.put.abort { (outputObject, error) in}
for (int i = 0; i<20; i++) {QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// Monitor the upload progress[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file}];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * fileUrl = result.location;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];}
for i in 1...10 {let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "exampleobject-".appendingFormat("%d", i);// Content of the object to uploadlet dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// ETag of the filelet eTag = result.eTag// File download linklet location = result.location;// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// Monitor the upload progressput.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);}
for (int i = 0; i<20; i++) {QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// Customize the threshold to trigger multipart upload. By default, multipart upload is triggered when the file size is greater than 1 MBput.mutilThreshold = 10 *1024*1024;// Monitor the upload progress[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file}];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * location = result.location;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];}
for i in 1...10 {let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "exampleobject-".appendingFormat("%d", i);// Content of the object to uploadlet dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// Customize the threshold to trigger multipart upload. By default, multipart upload is triggered when the file size is greater than 1 MBput.mutilThreshold = 10 *1024*1024;// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// ETag of the filelet eTag = result.eTag// File download linklet location = result.location;// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// Monitor the upload progressput.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);}
for (int i = 0; i<20; i++) {QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// Customize the part size. Default value: 1 MBput.sliceSize = 10 *1024*1024;// Monitor the upload progress[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file}];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * location = result.location;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];}
for i in 1...10 {let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "exampleobject-".appendingFormat("%d", i);// Content of the object to uploadlet dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// Customize the part size. Default value: 1 MBput.sliceSize = 10 *1024*1024// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// ETag of the filelet eTag = result.eTag// File download linklet location = result.location;// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// Monitor the upload progressput.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);}
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typeput.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// Use `trafficLimit` to limit the upload speed, in bit/s. The speed range is 819200 to 838860800, that is, 100 KB/s to 100 MB/s.put.trafficLimit = 819200;// Monitor the upload progress[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file}];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * location = result.location;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "exampleobject-".appendingFormat("%d", i);// Content of the object to uploadlet dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// Use `trafficLimit` to limit the upload speed, in bit/s. The speed range is 819200 to 838860800, that is, 100 KB/s to 100 MB/s.put.trafficLimit = 819200;// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// ETag of the filelet eTag = result.eTag// File download linklet location = result.location;// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// Monitor the upload progressput.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent Number of bytes to send in this request (a large file may require multiple requests)// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Total number of bytes expected to send, i.e. the size of the file};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// Name of the directory to createput.object = @"dir1";// Content of the object to be uploaded. If you need to create a directory, you only need to use a null string to generate `NSData`put.body = [@"" dataUsingEncoding:NSUTF8StringEncoding];// Monitor the upload result[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// Obtain the download link of the file uploaded using result.locationNSString * location = result.location;}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = "dir/";// Content of the object to uploadlet dataBody:NSData = "".data(using: .utf8)! as NSData;put.body = dataBody;// Monitor the upload resultput.setFinish { (result, error) in// Get the upload resultif let result = result {// File download linklet location = result.location;} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
/
; otherwise, it will be identified as a folder.QCloudPutObjectRequest* put = [QCloudPutObjectRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.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"put.object = @"exampleobject";// Content of the object. You can pass in variables in `NSData*` or `NSURL*` format.put.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];[put setFinishBlock:^(id result, NSError *error) {// result contains response headers.// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] PutObject:put];
let putObject = QCloudPutObjectRequest<AnyObject>.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketputObject.bucket = "examplebucket-1250000000";// Content of the object to be uploaded. You can pass variables of the `NSData*` or `NSURL*` typelet dataBody:NSData? = "wrwrwrwrwrw".data(using: .utf8) as NSData?;putObject.body = dataBody!;// 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"putObject.object = "exampleobject";putObject.finishBlock = {(result,error) inif let result = result {// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putObject(putObject);
Initiate Multipart Upload
and get the UploadId
.UploadId
to upload the parts with Upload Part - Copy
.Complete Multipart Upload
.UploadId
of the multipart upload, you can query the multipart upload job with List Multipart Uploads
to get the UploadId
of the corresponding file.UploadId
to list the uploaded parts with List Parts
.UploadId
to upload the remaining parts with Upload Part
.Complete Multipart Upload
.UploadId
of the multipart upload, you can query the multipart upload job with List Multipart Uploads
to get the UploadId
of the corresponding file.Abort Multipart Upload
.List Multipart Uploads
) is used to query in-progress multipart uploads in a specified bucket.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) {// Get the information on in-progress multipart uploads from result// Object in the ongoing multipart uploadNSArray<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 unfinished multipart uploads.let uploads = result.uploads;} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().listBucketMultipartUploads(listParts);
uploadId
.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 upload. This ID is required for subsequent uploads. 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 upload. This ID is required for subsequent uploads. Please save it for future use.self.uploadId = result.uploadId;} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().initiateMultipartUpload(initRequest);
Upload Part
) is used to upload an object in parts.QCloudUploadPartRequest* request = [QCloudUploadPartRequest new];// 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";// Part numberrequest.partNumber = 1;// The ID of the multipart upload. When you use the Initiate Multipart Upload API to initialize a multipart upload, you will get an uploadIdrequest.uploadId = uploadId;// Uploaded data. NSData *, NSURL (local URL), and QCloudFileOffsetBody * are supported.request.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];[request setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// Upload progress// bytesSent Number of new bytes sent// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Target number of bytes expected to send}];[request setFinishBlock:^(QCloudUploadPartResult* outputObject, NSError *error) {QCloudMultipartInfo *part = [QCloudMultipartInfo new];// Get the ETag of the uploaded part.part.eTag = outputObject.eTag;part.partNumber = @"1";// Save it for future use after the upload is completeself.parts = @[part];// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] UploadPart:request];
let uploadPart = QCloudUploadPartRequest<AnyObject>.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketuploadPart.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"uploadPart.object = "exampleobject";uploadPart.partNumber = 1;// ID of the multipart uploadif let uploadId = self.uploadId {uploadPart.uploadId = uploadId;}// Example filelet dataBody:NSData? = "wrwrwrwrwrwwrwrwrwrwrwwwrwrw".data(using: .utf8) as NSData?;uploadPart.body = dataBody!;uploadPart.setFinish { (result, error) inif let result = result {let mutipartInfo = QCloudMultipartInfo.init();// Get the ETag of the part.mutipartInfo.eTag = result.eTag;mutipartInfo.partNumber = "1";// Save it for completing the uploadself.parts = [mutipartInfo];// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}uploadPart.sendProcessBlock = {(bytesSent,totalBytesSent,totalBytesExpectedToSend) in// Upload progress// bytesSent Number of new bytes sent// totalBytesSent Total number of bytes sent so far// totalBytesExpectedToSend Target number of bytes expected to send}QCloudCOSXMLService.defaultCOSXML().uploadPart(uploadPart);
List Parts
) is used to query the uploaded parts of a multipart upload.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 Upload request returns an upload ID that uniquely identifies the upload.request.uploadId = uploadId;[request setFinishBlock:^(QCloudListPartsResult * _Nonnull result,NSError * _Nonnull error) {// Get the information on uploaded parts 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 Upload request returns an upload ID that uniquely identifies the upload.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 upload of a file.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 upload to be queried. This ID can be obtained from `QCloudInitiateMultipartUploadResult`, i.e. the result of the multipart upload initialization requestcompleteRequst.uploadId = uploadId;// Information on the uploaded partsQCloudCompleteMultipartUploadInfo *partInfo = [QCloudCompleteMultipartUploadInfo new];NSMutableArray * parts = [self.parts mutableCopy];// Sort the uploaded 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 upload result from result// Obtain the CRC64 value of the objectNSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[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 upload to be queried. This ID can be obtained from// `QCloudInitiateMultipartUploadResult`, i.e., the result of the multipart upload initialization requestcomplete.uploadId = "exampleUploadId";if let uploadId = self.uploadId {complete.uploadId = uploadId;}// Information on the uploaded partslet 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) inif let result = result {// ETag of the filelet eTag = result.eTag// Unsigned file URLlet location = result.location// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().completeMultipartUpload(complete);
Abort Multipart Upload
) is used to abort a multipart upload and delete the uploaded parts.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 upload to be aborted.// This ID can be obtained from `QCloudInitiateMultipartUploadResult`, i.e. the result of the multipart upload initialization requestabortRequest.uploadId = @"exampleUploadId";[abortRequest setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains information such as the ETag or custom headers in the response.NSDictionary * 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 upload to be queried. This ID can be obtained from// `QCloudInitiateMultipartUploadResult`, i.e., the result of the multipart upload 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?