public async Task <ResponseModel> DeleteObject(string buketName) { try { string bucket = _buketName + "-" + _appid; //存储桶名称 格式:BucketName-APPID string key = "exampleobject"; //对象在存储桶中的位置,即称对象键. DeleteObjectRequest request = new DeleteObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 DeleteObjectResult result = await Task.FromResult(_cosXml.DeleteObject(request)); return(new ResponseModel { Code = 200, Message = result.GetResultInfo() }); } catch (CosClientException clientEx) { return(new ResponseModel { Code = 0, Message = "CosClientException: " + clientEx.Message }); } catch (CosServerException serverEx) { return(new ResponseModel { Code = 0, Message = "CosServerException: " + serverEx.GetInfo() }); } }
internal static void DeleteObject(CosXmlServer cosXml, string cosKey) { DeleteObjectRequest request = new DeleteObjectRequest(bucket, cosKey); DeleteObjectResult result = cosXml.DeleteObject(request); Console.WriteLine(result.GetResultInfo()); }
/// <summary> /// 删除对象 /// </summary> /// <param name="containerName">容器(Bucket)的地址</param> /// <param name="blobName">文件名称</param> public async Task DeleteBlob(string containerName, string blobName) { var request = new DeleteObjectRequest(_tcConfig.BucketName, $"{containerName}/{blobName}"); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); var response = _cosXmlServer.DeleteObject(request); await response.HandlerError("删除对象出错!"); }
public override void DeleteFile(IVirgoFile file) { var ossSettings = _config.FileUploadOptions.Settings.Where(x => x.Key.ToLower() == "tencos").Select(x => x.Value).FirstOrDefault(); FileHandlerOptions groupInfo = null; if (string.IsNullOrEmpty(file.ExtraInfo)) { groupInfo = ossSettings?.FirstOrDefault(); } else { groupInfo = ossSettings?.Where(x => x.GroupName.ToLower() == file.ExtraInfo.ToLower()).FirstOrDefault(); if (groupInfo == null) { groupInfo = ossSettings?.FirstOrDefault(); } } if (groupInfo == null) { return; } try { CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(40000) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(false) //设置默认 HTTPS 请求 .SetAppid(groupInfo.AppId) //设置腾讯云账户的账户标识 APPID .SetRegion(groupInfo.GroupName) .Build(); long durationSecond = 600; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(groupInfo.Secret, groupInfo.Key, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); string bucket = groupInfo.GroupLocation + "-" + groupInfo.AppId; string key = file.FileName; //对象键 DeleteObjectRequest request = new DeleteObjectRequest(bucket, key); //执行请求 DeleteObjectResult result = cosXml.DeleteObject(request); //请求成功 Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } return; }
/// <summary> /// /// </summary> /// <param name="bucket"></param> /// <param name="key"></param> /// <returns></returns> public bool Delete(string bucket, string key) { try { DeleteObjectRequest request = new DeleteObjectRequest(bucket, key); //执行请求 DeleteObjectResult result = cosXml.DeleteObject(request); return(true); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); Debug.WriteLine("CosClientException: " + clientEx); return(false); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Debug.WriteLine("CosServerException: " + serverEx.GetInfo()); return(false); } }
public Task <bool> Delete(string bucket, string fileKey) { var result = server.DeleteObject(new DeleteObjectRequest(bucket, fileKey)); return(Task.FromResult(true)); }