Aliyun.OSS.SDK.AspNetCore
1.0.0
dotnet add package Aliyun.OSS.SDK.AspNetCore --version 1.0.0
NuGet\Install-Package Aliyun.OSS.SDK.AspNetCore -Version 1.0.0
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="Aliyun.OSS.SDK.AspNetCore" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aliyun.OSS.SDK.AspNetCore --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Aliyun.OSS.SDK.AspNetCore, 1.0.0"
#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.
// Install Aliyun.OSS.SDK.AspNetCore as a Cake Addin #addin nuget:?package=Aliyun.OSS.SDK.AspNetCore&version=1.0.0 // Install Aliyun.OSS.SDK.AspNetCore as a Cake Tool #tool nuget:?package=Aliyun.OSS.SDK.AspNetCore&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Aliyun.OSS.SDK.AspNetCore
介绍
阿里云对象存储 Asp.Net Core 服务注册扩展
- 安装
Install-Package Aliyun.OSS.SDK.AspNetCore
dotnet add package Aliyun.OSS.SDK.AspNetCore
- 注册服务
builder.Services.AddOSSAliyun(conn =>
{
conn.Endpoint = "oss-cn-beijing.aliyuncs.com";
conn.AccessKeySecret = "R28E5Exxxxxxxxxxxqa7terCWfGIVVIh";
conn.AccessKeyId = "LTxxxxxxxx5oAG";
});
- 构造函数注入OssClient
[Route("api/[controller]/[action]")]
[ApiController]
public class FileController : ControllerBase
{
private readonly OssClient _ossClient;
public FileController(OssClient ossClient)
{
_ossClient = ossClient;
}
[HttpPost]
public void CreateBucket(string bucketName)
{
try
{
if (!_ossClient.DoesBucketExist(bucketName))
{
var result = _ossClient.CreateBucket(bucketName);
Console.WriteLine("Create bucket, ETag: {0} ", result.Name);
}
else
{
Console.WriteLine("bucket Exist, ETag: {0} ", bucketName);
}
}
catch (Exception ex)
{
Console.WriteLine("Put object failed, {0}", ex.Message);
}
}
[HttpPost]
public void PutObject(IFormFile file)
{
try
{
var stream = file.OpenReadStream();
// 上传文件。
var result = _ossClient.PutObject("onevip", file.FileName, stream);
Console.WriteLine("Put object succeeded, ETag: {0} ", result.ETag);
}
catch (Exception ex)
{
Console.WriteLine("Put object failed, {0}", ex.Message);
}
}
[HttpPost]
public void Download()
{
try
{
// 下载文件。
var result = _ossClient.GetObject("onevip", "FreeRedis.AspNetCore.1.0.0.nupkg");
using (var requestStream = result.Content)
{
using (var fs = System.IO.File.Open($"D:\\{result.Key}", FileMode.OpenOrCreate))
{
int length = 4 * 1024;
var buf = new byte[length];
do
{
length = requestStream.Read(buf, 0, length);
fs.Write(buf, 0, length);
} while (length != 0);
}
}
Console.WriteLine("Get object succeeded");
}
catch (OssException ex)
{
Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
}
catch (Exception ex)
{
Console.WriteLine("Failed with error info: {0}", ex.Message);
}
}
}
Product | Versions 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.
-
.NETStandard 2.1
- Aliyun.OSS.SDK.NetCore (>= 2.13.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
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 | 213 | 7/21/2023 |
阿里云对象存储服务注册