AWS SDK for .NET#

S3 access using aws-sdk-net#

To connect AWS SDK for .NET (AWSSDK.core version 3.7.400.53 or later) to K2 Cloud object storage, follow the next steps:

  1. Get API access settings in the cloud management console. Click the user login in the top right corner, select Profile Get API access settings. In the downloaded file, specify your project ID for the*C2_PROJECT* variable.

  2. Add the downloaded settings to the environment variables:

    For Windows, convert the settings file and export the environment variables:

    C:\> c2rc-convert path\to\c2rc.sh path\to\c2rc.bat
    C:\> call path\to\c2rc.bat
    

    To convert settings, use c2rc-convert utility from c2-client package.

    For Linux, export the environment variables:

    source path/to/c2rc.sh
    
  3. Create a .NET project and add packages AWSSDK.Core and AWSSDK.S3 from the aws-sdk documentation to it.

    dotnet new console --name awsdotnets3 && cd awsdotnets3
    dotnet add package AWSSDK.Core
    dotnet add package AWSSDK.S3
    
  4. Go to the project directory and create Program.cs file with the following block:

    Program.cs
       // Получение значения переменной окружения S3_URL K2 Cloud
       string? serviceUrl = Environment.GetEnvironmentVariable("S3_URL");
    
       // Проверка наличия переменной окружения S3_URL K2 Cloud
       if (string.IsNullOrWhiteSpace(serviceUrl))
       {
          Console.WriteLine("Environment variable S3_URL is not set or empty.");
          return;
       }
    
       // Настройка конфигурации клиента S3
       var config = new AmazonS3Config
       {
          SignatureVersion = "2",  // Используем Signature Version 2
          ServiceURL = serviceUrl  // S3_URL K2 Cloud
       };
    
       client = new AmazonS3Client(config);
    
  5. Build and run the project as follows:

    dotnet build
    dotnet run