Object Storage Service

Products

Object Storage Service

SDK-.NET

Overview

This document is based on AWS .NET SDK. JD Cloud object storage service supports the AWS S3 interface. For more information about compatible interfaces, see Compatible Interface.

Environment Preparation

Please use the .NET Framework 3.5 or platform of higher version for development.

Installation Mode

To install the AWS SDK for .NET, please refer to the installation [AWS-SDK Assembly](https://docs.aws.amazon.com/en_us/sdk-for-net/v3/developer-guide/net-dg-install -assemblies.html?shortFooter=true).

Initialize Client

You can create S3Client to manage OSS resources such as bucket and file. To launch an OSS request using the .NET SDK, you need to initialize an S3Client with your AccessKey and SecretKey and modify the default configuration items of Config as needed.

The following is an example of creating a client. For more .NET SDK examples, please access [S3 .NET Example Code](https://docs.aws.amazon.com/en_us/sdk-for-net/v3/developer-guide/ S3-apis-intro.html?shortFooter=true).


using Amazon.S3;

namespace Amazon.Samples.S3
{
    public class Test
    {
        const string accessKeyId = "<yourAccessKeyId>";
        const string accessKeySecret = "<yourAccessKeySecret>";
        const string endpoint = "s3.cn-north-1.jdcloud-oss.com";
        
        private static IAmazonS3 s3Client;
        
        public static void Main()
        {
            var s3ClientConfig = new AmazonS3Config
            {
                ServiceURL = endpoint,
                SignatureVersion = "4",
                UseHttp = true,
            };
            s3Client = new AmazonS3Client(accessKeyId, accessKeySecret, s3ClientConfig);
           
            //use s3 client to create bucket、put object....
        }
    }
}

Upload object

Use .NET s3Client to upload file.


// Create a PutObject request
PutObjectRequest request = new PutObjectRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
    ContentBody = "This is sample content...",
    UseChunkEncoding = false
};
 
// Put object
PutObjectResponse response = s3Client.PutObject(request);

Note: UseChunkEncoding shall be set false to disable Chunked-Encoding

Update Time:2019-07-24 18:45:33