kalveygroup.com – After installing Alibaba Cloud OSS SDK, the next challenge is what syntaxes are being used to manage OSS resources. In this post, we will cover several basic SDK usages to manage Alibaba Cloud OSS.

Prerequisite

1. Visual Studio 2010 or above. In this example, we will use Visual Studio 2017
2. Internet Connection
3. AccessKey which you can discover in our previous post
4. Aliyun.OSS.SDK (How to install OSS SDK)

Terms

1. Endpoint
This is the domain name

2. accessKeyId and accessKeySecret
This is the pair of the API Access Key that will be used to manage the OSS

3. bucketName
This is the bucket name. Make sure the bucket name is the same as the one created in Alibaba Cloud Console.

Create New Bucket

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
client.CreateBucket(bucketName);

 

Remove Bucket

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 
client.DeleteBucket(bucketName);


Get Bucket List

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
var buckets = client.ListBuckets(); foreach (var bucket in buckets) { Console.WriteLine(bucket.Name + ", " + bucket.Location + ", " + bucket.Owner); }


Upload Object to Bucket

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 
client.PutObject(bucketName, key, filePathToUpload);


Download Object From Bucket

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
var object = ossClient.GetObject(bucketName, key);	


Get Object List

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
var listResult = client.ListObjects(bucketName);
foreach (var summary in listResult.ObjectSummaries)
   {
      Console.WriteLine(summary.Key);
   }


Remove Object From Bucket

OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
client.DeleteObject(bucketName, key)