public static void DeleteBucket(string bucketName) { try { client.DeleteBucket(bucketName); Console.WriteLine("Delete bucket name:{0} succeeded ", bucketName); } catch (OssException ex) { Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); } }
public void CreateBucketWithColdArchiveStorageClassTest() { var client = new OssClient("http://oss-ap-southeast-2.aliyuncs.com", Config.AccessKeyId, Config.AccessKeySecret); //get a random bucketName var bucketName = OssTestUtils.GetBucketName(_className); //assert bucket does not exist Assert.IsFalse(OssTestUtils.BucketExists(client, bucketName), string.Format("Bucket {0} should not exist before creation", bucketName)); //create a new bucket var request = new CreateBucketRequest(bucketName, StorageClass.ColdArchive, CannedAccessControlList.PublicReadWrite); client.CreateBucket(request); OssTestUtils.WaitForCacheExpire(); Assert.IsTrue(OssTestUtils.BucketExists(client, bucketName), string.Format("Bucket {0} should exist after creation", bucketName)); //delete the new created bucket client.DeleteBucket(bucketName); OssTestUtils.WaitForCacheExpire(); Assert.IsFalse(OssTestUtils.BucketExists(client, bucketName), string.Format("Bucket {0} should not exist after deletion", bucketName)); }
public static void CreateBucket(string bucketName) { var created = false; try { client.CreateBucket(bucketName); created = true; Console.WriteLine("Created bucket name: " + bucketName); client.CreateBucket(bucketName); } catch (OssException ex) { if (ex.ErrorCode == OssErrorCode.BucketAlreadyExists) { Console.WriteLine("Bucket '{0}' already exists, please modify and recreate it.", bucketName); } else { Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); } } finally { if (created) { client.DeleteBucket(bucketName); } } }
public override void OnApplicationShutdown(ApplicationShutdownContext context) { var ossClient = new OssClient(_endPoint, _accessKeyId, _accessKeySecret); if (ossClient.DoesBucketExist(_bucketName)) { ossClient.DeleteBucket(_bucketName); } }
public Task <bool> RemoveBucketAsync(string bucketName) { if (string.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException(nameof(bucketName)); } _client.DeleteBucket(bucketName); return(Task.FromResult(true)); }
public void TestDeleteBucket() { OssClient ossClient = GetOssClient(); DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest(); deleteBucketRequest.RegionId = "cn-north-1"; deleteBucketRequest.Bucketname = "DotNetTest"; var result = ossClient.DeleteBucket(deleteBucketRequest).Result; _output.WriteLine(JsonConvert.SerializeObject(result)); }
/// <summary> /// 删除存储空间 /// </summary> private static void DeleteBucket() { try { _client.DeleteBucket(_bucketName); Console.WriteLine("删除存储空间成功"); } catch (Exception ex) { Console.WriteLine("删除存储空间失败", ex.Message); } }
public static void CreateEmptyFolder() { const string accessKeyId = "<your access key id>"; const string accessKeySecret = "<your access key secret>"; const string endpoint = "<valid endpoint>"; var client = new OssClient(endpoint, accessKeyId, accessKeySecret); const string bucketName = "<your bucket>"; // Note: key treats as a folder and must end with slash. const string key = "yourfolder/"; var created = false; var uploaded = false; try { // create bucket client.CreateBucket(bucketName); created = true; Console.WriteLine("Created bucket name: " + bucketName); // put object with zero bytes stream. using (MemoryStream memStream = new MemoryStream()) { PutObjectResult ret = client.PutObject(bucketName, key, memStream); uploaded = true; Console.WriteLine("Uploaded empty object's ETag: " + ret.ETag); } } catch (OssException ex) { if (ex.ErrorCode == OssErrorCode.BucketAlreadyExists) { Console.WriteLine("Bucket '{0}' already exists, please modify and recreate it.", bucketName); } else { Console.WriteLine("CreateBucket Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); } } finally { if (uploaded) { client.DeleteObject(bucketName, key); } if (created) { client.DeleteBucket(bucketName); } } }
/// <summary> /// 删除容器 /// </summary> /// <param name="containerName"></param> public async Task DeleteContainer(string containerName) { try { await Task.Run(() => { _ossClient.DeleteBucket(containerName); }); } catch (Exception ex) { throw new StorageException(StorageErrorCode.PostError.ToStorageError(), new Exception(ex.ToString())); } }
public void DeleteBucket(string bucketName) { try { var client = new OssClient(_endPoint, _accessKeyId, _accessKeySecret); client.DeleteBucket(bucketName); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Delete Bucket /// </summary> public bool DeleteBucket() { try { client.DeleteBucket(bucketName); return(true); } catch (OssException ex) { lastError = ex; return(false); } }
//删除存储空间 public void DeleteBucket(string bucketName) { var client = new OssClient(endpoint, accessKeyId, accessKeySecret); try { client.DeleteBucket(bucketName); Console.WriteLine("删除成功!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
protected void btnDeleteBucket_Click(object sender, EventArgs e) { OssClient ossClient = new OssClient(accessId, accessKey); try { ossClient.DeleteBucket(bucketName); Console.WriteLine("删除成功!Bucket: " + bucketName); } catch (OssException ex) { // RequestID和HostID可以在有问题时用于联系客服诊断异常。 Console.WriteLine(string.Format("创建失败。错误代码:{0}; 错误消息:{1}。\nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId)); } }
public async Task DeleteContainerAsync(string containerName) { try { await Task.Run(() => _ossClient.DeleteBucket(containerName)); } catch (Exception e) { if (e.IsOssStorageException()) { var ex = e.Convert() as StorageException; //不存在不报错 if (ex.ErrorCode == (int)StorageErrorCode.InvalidContainerName) { return; } throw ex; } throw; } }
public void CreateAndDeleteBucketDefaultRegionTest() { var settings = AccountSettings.Load(); //point to default region var ossClient = new OssClient(settings.OssEndpoint, settings.OssAccessKeyId, settings.OssAccessKeySecret); //get a random bucketName var bucketName = OssTestUtils.GetBucketName(_className); //assert bucket does not exist Assert.IsFalse(OssTestUtils.BucketExists(ossClient, bucketName), string.Format("Bucket {0} should not exist before creation", bucketName)); //create a new bucket ossClient.CreateBucket(bucketName); Assert.IsTrue(ossClient.DoesBucketExist(bucketName), string.Format("Bucket {0} should exist after creation", bucketName)); //delete the bucket ossClient.DeleteBucket(bucketName); Assert.IsFalse(ossClient.DoesBucketExist(bucketName), string.Format("Bucket {0} should not exist after deletion", bucketName)); }
public static void CreateBucket(string bucketName) { const string accessKeyId = "<your access key id>"; const string accessKeySecret = "<your access key secret>"; const string endpoint = "<valid host name>"; var client = new OssClient(endpoint, accessKeyId, accessKeySecret); var created = false; try { client.CreateBucket(bucketName); created = true; Console.WriteLine("Created bucket name: " + bucketName); client.CreateBucket(bucketName); } catch (OssException ex) { if (ex.ErrorCode == OssErrorCode.BucketAlreadyExists) { Console.WriteLine("Bucket '{0}' already exists, please modify and recreate it.", bucketName); } else { Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); } } finally { if (created) { client.DeleteBucket(bucketName); } } }
public async Task deleteBucket(string bucketName) { await _ossClient.DeleteBucket(bucketName); this.Remove(this.First(x => x.Name == bucketName)); }