/// 删除多个对象 public void DeleteMultiObject() { //.cssg-snippet-body-start:[delete-multi-object] try { string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(bucket); //设置返回结果形式 request.SetDeleteQuiet(false); //对象key string key = "exampleobject"; //对象键 List <string> objects = new List <string>(); objects.Add(key); request.SetObjectKeys(objects); //执行请求 DeleteMultiObjectResult result = cosXml.DeleteMultiObjects(request); //请求成功 Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
public static void test(CosXml cosXml) { List <string> keys = new List <string>(); string bucket = "android-demo-ap-guangzhou"; GetBucketRequest getBucket = new GetBucketRequest(bucket); getBucket.Region = EnumUtils.GetValue(CosRegion.AP_Guangzhou); getBucket.SetSign(COSXML.Utils.TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); GetBucketResult result = cosXml.GetBucket(getBucket); Console.WriteLine(result.GetResultInfo()); foreach (ListBucket.Contents content in result.listBucket.contentsList) { if (content != null) { keys.Add(content.key); } } if (keys.Count > 0) { COSXML.Model.Object.DeleteMultiObjectRequest deleteMults = new COSXML.Model.Object.DeleteMultiObjectRequest(bucket); deleteMults.SetSign(COSXML.Utils.TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); deleteMults.Region = EnumUtils.GetValue(CosRegion.AP_Guangzhou); deleteMults.SetObjectKeys(keys); COSXML.Model.Object.DeleteMultiObjectResult deleteMultisResult = cosXml.DeleteMultiObjects(deleteMults); Console.WriteLine(deleteMultisResult.GetResultInfo()); } ListMultiUploadsRequest listMultis = new ListMultiUploadsRequest(bucket); listMultis.Region = EnumUtils.GetValue(CosRegion.AP_Guangzhou); listMultis.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); ListMultiUploadsResult listMultisResult = cosXml.ListMultiUploads(listMultis); Console.WriteLine(listMultisResult.GetResultInfo()); if (listMultisResult.listMultipartUploads.uploads.Count > 0) { foreach (ListMultipartUploads.Upload upload in listMultisResult.listMultipartUploads.uploads) { if (upload == null) { continue; } string key = upload.key; string uploadId = upload.uploadID; COSXML.Model.Object.AbortMultiUploadRequest abort = new COSXML.Model.Object.AbortMultiUploadRequest(bucket, key, uploadId); abort.Region = EnumUtils.GetValue(CosRegion.AP_Guangzhou); abort.SetSign(COSXML.Utils.TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); COSXML.Model.Object.AbortMultiUploadResult abortResult = cosXml.AbortMultiUpload(abort); } } }
public async Task <bool> RemoveObjectAsync(string bucketName, List <string> objectNames) { if (string.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException(nameof(bucketName)); } if (objectNames == null || objectNames.Count == 0) { throw new ArgumentNullException(nameof(objectNames)); } bucketName = ConvertBucketName(bucketName); DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(bucketName); //设置返回结果形式 request.SetDeleteQuiet(false); request.SetObjectKeys(objectNames); DeleteMultiObjectResult result = _client.DeleteMultiObjects(request); return(await Task.FromResult(result.IsSuccessful())); }
public bool DeleteMutiObjects(List <string> keys) { try { //存储桶,格式:BucketName-APPID DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(options.Bucket); //设置返回结果形式 request.SetDeleteQuiet(false); //对象key //List<string> objects = new List<string>(); //objects.Add(key); request.SetObjectKeys(keys); //执行请求 DeleteMultiObjectResult result = cosXml.DeleteMultiObjects(request); //请求成功 // Console.WriteLine(result.GetResultInfo()); logger.LogInformation($"DeleteMutiObjects[{string.Join("|", keys)}]:{result.GetResultInfo()}"); } catch (COSXML.CosException.CosClientException clientEx) { logger.LogError(clientEx, $"DeleteObject"); return(false); //请求失败 //Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { logger.LogError(serverEx, $"DeleteObject"); return(false); //请求失败 // Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } return(true); }