/// 删除多个对象 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 AsyncMultiDeleteObject(COSXML.CosXml cosXml, string bucket, List <string> keys) { DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置返回结果形式 request.SetDeleteQuiet(false); //设置删除的keys request.SetObjectKeys(keys); //执行请求 cosXml.DeleteMultiObjects(request, delegate(CosResult result) { DeleteMultiObjectResult getObjectResult = result as DeleteMultiObjectResult; Console.WriteLine(getObjectResult.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void MultiDeleteObject(COSXML.CosXml cosXml, string bucket, List <string> keys) { try { DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置返回结果形式 request.SetDeleteQuiet(false); //设置删除的keys request.SetObjectKeys(keys); //执行请求 DeleteMultiObjectResult result = cosXml.DeleteMultiObjects(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public void MultiDeleteObject() { try { DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(bucket); //设置返回结果形式 request.SetDeleteQuiet(false); //设置删除的keys List <string> keys = new List <string>(); keys.Add(commonKey); keys.Add(multiKey); request.SetObjectKeys(keys); //执行请求 DeleteMultiObjectResult result = cosXml.DeleteMultiObjects(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.True(false); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
/// 指定前缀批量删除对象 public void DeletePrefix() { //.cssg-snippet-body-start:[delete-prefix] try { String nextMarker = null; // 循环请求直到没有下一页数据 do { string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID string prefix = "folder1/"; //指定前缀 GetBucketRequest listRequest = new GetBucketRequest(bucket); //获取 folder1/ 下的所有对象以及子目录 listRequest.SetPrefix(prefix); listRequest.SetMarker(nextMarker); //执行列出对象请求 GetBucketResult listResult = cosXml.GetBucket(listRequest); ListBucket info = listResult.listBucket; // 对象列表 List <ListBucket.Contents> objects = info.contentsList; // 下一页的下标 nextMarker = info.nextMarker; DeleteMultiObjectRequest deleteRequest = new DeleteMultiObjectRequest(bucket); //设置返回结果形式 deleteRequest.SetDeleteQuiet(false); //对象列表 List <string> deleteObjects = new List <string>(); foreach (var content in objects) { deleteObjects.Add(content.key); } deleteRequest.SetObjectKeys(deleteObjects); //执行批量删除请求 DeleteMultiObjectResult deleteResult = cosXml.DeleteMultiObjects(deleteRequest); //打印请求结果 Console.WriteLine(deleteResult.GetResultInfo()); } while (nextMarker != null); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
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); }