Giter Club home page Giter Club logo

huaweicloudobs's Introduction

HuaweiCloudObs

huawei cloud obs .net sdk

安装

安装nuget HuaweiCloudObs

使用

在appsettings.json里添加配置

"HuaweiCloudObs": {
    "EndPoint": "obs.cn-east-3.myhuaweicloud.com",
    "AccessKey": "xxx",
    "SecretKey": "xxx"
  }

在Startup.cs的ConfigureService()方法里加入完成注入. 需传入IConfigurationRoot

services.AddHuaweiCloudObs(configuration);

需要使用的地方注入对应接口 以Abp的appservice为例,如MyAppService. 直接使用Controller也是差不多,注入后即可使用

public class MyObsAppService : ApplicationService
{
  private readonly IObsObjectApi _objectApi;
  public MyObsAppService(IObsObjectApi api)
  {
    api.Bucket = "MyBucket";//设置bucket,可以放在配置里注入,也可存入数据库后读取
    _objectApi = api;
  }

  public async Task UploadAsync(IFormFile file, string name)
  {
     var bytes = await file.GetAllBytes();
     await _objectApi.PutAsync(name, file);
  }

  public Task DeleteAsync(string name)
  {
    return _objectApi.DeleteAsync(name);
  }

  public async Task DeleteBatchAsync(IEnumerable<string> names)
  {
    var result = await _objectApi.DeleteBatchAsync(new DeleteObjectsRequest
    {
      Objects = name.Select(f => new DeleteObject{ Key = f}).ToList()
    });

    if(result.Errors.Count > 0)
    {
      //存在删除失败对象
      //TODO: 删除失败处理
    }
  }
}

路线图

对象操作

桶操作

基础操作

高级操作

huaweicloudobs's People

Contributors

lginc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.