DEV Community

chuongmep
chuongmep

Posted on

Use OSS Bucket SDK .NET Autodesk Platform Services (APS)

The Autodesk Platform Services (APS) SDK for .NET helps .NET developer create applications that leverage the various APS services: Model Derivative, Data Management, OSS, Webhooks. More services soon.

Buckets are virtual container within the Object Storage Service (OSS), which you can use to store and manage objects (files) in the cloud.

First, you need to install the package aps-sdk-net library :

  <PackageReference Include="Autodesk.Oss" Version="2.0.0" />
Enter fullscreen mode Exit fullscreen mode

Create a Bucket

So now you can use some code like this to create an bucket:

using Autodesk.Oss.Model;
using Autodesk.SDKManager;
var sdkManager = SdkManagerBuilder
            .Create()
            .Add(new ApsConfiguration())
            .Add(ResiliencyConfiguration.CreateDefault())
            .Build();
var _ossClient = new OssClient(sdkManager);
Bucket bucket = await _ossClient.CreateBucketAsync(
            accessToken: token,
            xAdsRegion: Region.US,
            bucketsPayload: new CreateBucketsPayload()
            {
                BucketKey = bucketKey,
                PolicyKey = PolicyKey.Temporary
            });
Enter fullscreen mode Exit fullscreen mode

Get Bucket Details

Bucket bucket = await _ossClient.GetBucketDetailsAsync(
             accessToken: token,
             bucketKey: bucketKey);
Enter fullscreen mode Exit fullscreen mode

Get Bucket :

Buckets buckets = await _ossClient.GetBucketsAsync(accessToken: token);
Enter fullscreen mode Exit fullscreen mode

Delete Bucket

HttpResponseMessage httpResponseMessage = await _ossClient.DeleteBucketAsync(
             accessToken: token,
             bucketKey: bucketKey);
Enter fullscreen mode Exit fullscreen mode

Upload an object to bucket

ObjectDetails objectDetails = await _ossClient.UploadObjectAsync(
            accessToken: token,
            bucketKey: bucketKey,
            objectKey: objectKey,
            sourceToUpload: sourceToUpload,
            cancellationToken: CancellationToken.None);
Enter fullscreen mode Exit fullscreen mode

Copy object from bucket

ObjectDetails objectDetails = await _ossClient.CopyToAsync(
            accessToken: token,
            bucketKey: bucketKey,
            objectKey: objectKey,
            newObjName: newObjName);
Enter fullscreen mode Exit fullscreen mode

Download Bucket Object

    await _ossClient.DownloadObjectAsync(
            accessToken: token,
            bucketKey: bucketKey,
            objectKey: objectKey,
            filePath: filePath,
            cancellationToken: CancellationToken.None);
Enter fullscreen mode Exit fullscreen mode

Get Object Info

BucketObjects bucketObjects = await _ossClient.GetObjectsAsync(
            accessToken: token,
            bucketKey: bucketKey);
Enter fullscreen mode Exit fullscreen mode

Detele Object Info

HttpResponseMessage httpResponseMessage = await _ossClient.DeleteObjectAsync(
            accessToken: token,
            bucketKey: bucketKey,
            objectKey: objectKey);
Enter fullscreen mode Exit fullscreen mode

Reference

Top comments (1)

Collapse
 
chuongmep profile image
chuongmep

Test