ObsNet 1.0.0-beta.10

This is a prerelease version of ObsNet.
dotnet add package ObsNet --version 1.0.0-beta.10
                    
NuGet\Install-Package ObsNet -Version 1.0.0-beta.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ObsNet" Version="1.0.0-beta.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ObsNet" Version="1.0.0-beta.10" />
                    
Directory.Packages.props
<PackageReference Include="ObsNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ObsNet --version 1.0.0-beta.10
                    
#r "nuget: ObsNet, 1.0.0-beta.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ObsNet@1.0.0-beta.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ObsNet&version=1.0.0-beta.10&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ObsNet&version=1.0.0-beta.10&prerelease
                    
Install as a Cake Tool

华为OBS存储 API

实现了对华为OBS存储的API调用,支持文件的上传、下载、删除等操作。

目录

使用方法

安装依赖

Install-Package ObsNet

配置文件

{
  "OBS": {
    "Endpoint": "https://obs.[Location].myhuaweicloud.com",
    "ApiKey": "[Access Key Id]:[Secret Access Key]",
    "Location": "[Location]",
    "Bucket": "[Bucket Name]"
  }
}

使用示例

Init

    var endpoint = new Uri(configuration["OBS:Endpoint"]!);
    var key = configuration["OBS:ApiKey"];
    var apiKeyCredential = new ApiKeyCredential(key!);
    var serviceClient = new ObsNetClient(endpoint, apiKeyCredential);
    var bucketName = configuration["OBS:Bucket"];

CreateBucket

[TestMethod()]
public void GetItemsTest()
{
    try
    {
        var client = serviceClient.GetBucketClient();
        var result = client.GetBucketItems(bucketName, maxKeys: 1);
        Assert.IsNotNull(result?.Value);
        var res = (BucketItemsResponse)result.Value;
        Assert.IsNotNull(res?.Contents);
        Console.WriteLine(result.GetRawResponse().Content.ToString());
    }
    catch (ClientResultException ex)
    {
        Console.WriteLine(ex.GetRawResponse()?.Content.ToString());
        throw;
    }
}

//upload
[TestMethod()]
public async Task UploadTest()
{
    try
    {
        var tags = new Dictionary<string, string>
        {
            { "tag1", "value1" },
            { "tag2", "中/文" }
        };
        var metadata = new Dictionary<string, string>
        {
            { "key1", "value1" },
            { "key2", "中/文" }
        };
        var fileName = "sub/中文.txt";
        var client = serviceClient.GetBucketClient();
        var options = new RequestOptions();
        options.SetHeader("Content-Type", "application/octet-stream");
        foreach (var item in metadata)
        {
            options.AddHeader($"x-obs-meta-{item.Key}", Uri.EscapeDataString(item.Value));
        }
        var tagging = string.Join("&", tags.Select(c => $"{c.Key}={Uri.EscapeDataString(c.Value)}"));
        options.SetHeader("x-obs-tagging", tagging);
        var data = BinaryData.FromString("hello!");
        var result = await client.UploadObjectAsync(fileName, bucketName, BinaryContent.Create(data), options);
        Assert.IsNotNull(result);
    }
    catch (ClientResultException ex)
    {
        Console.WriteLine(ex.GetRawResponse()?.Content.ToString());
        throw;
    }
}

//download
[TestMethod()]
public async Task DownloadTest()
{
    try
    {
        var fileName = "sub/中文.txt";
        var client = serviceClient.GetBucketClient();
        var result = await client.DownloadObjectAsync(fileName, bucketName);
        Assert.IsNotNull(result?.Value);
        Console.WriteLine(result?.Value.ToString());
    }
    catch (ClientResultException ex)
    {
        Console.WriteLine(ex.GetRawResponse()?.Content.ToString());
        throw;
    }
}

//delete
[TestMethod()]
public async Task DeleteTest()
{
    try
    {
        var fileName = "sub/中文.txt";
        var client = serviceClient.GetBucketClient();
        var result = await client.DeleteObjectAsync(fileName, bucketName);
        Assert.IsNotNull(result);
    }
    catch (ClientResultException ex)
    {
        Console.WriteLine(ex.GetRawResponse()?.Content.ToString());
        throw;
    }
}

//create bucket
[TestMethod()]
public async Task CreateBucketTest()
{
    var location = configuration["OBS:Location"];
    var client = serviceClient.GetManagerClient();
    try
    {
        var result = await client.CreateBucketAsync(bucketName, location);
        Assert.IsNotNull(result);
    }
    catch (ClientResultException ex)
    {
        Console.WriteLine(ex.GetRawResponse()?.Content.ToString());
        throw;
    }
}

//list buckets
[TestMethod()]
public void ListBucketsTest()
{
    try
    {
        var client = serviceClient.GetManagerClient();
        var result = client.ListBuckets(BucketType.OBJECT);
        Assert.IsNotNull(result?.Value);
        //Console.WriteLine(result.GetRawResponse().Content.ToString());
    }
    catch (ClientResultException ex)
    {
        Console.WriteLine(ex.GetRawResponse()?.Content.ToString());
        throw;
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-beta.10 201 11/25/2025