BorgNet.MinIO
1.0.0
dotnet add package BorgNet.MinIO --version 1.0.0
NuGet\Install-Package BorgNet.MinIO -Version 1.0.0
<PackageReference Include="BorgNet.MinIO" Version="1.0.0" />
paket add BorgNet.MinIO --version 1.0.0
#r "nuget: BorgNet.MinIO, 1.0.0"
// Install BorgNet.MinIO as a Cake Addin #addin nuget:?package=BorgNet.MinIO&version=1.0.0 // Install BorgNet.MinIO as a Cake Tool #tool nuget:?package=BorgNet.MinIO&version=1.0.0
Minio使用 NuGet
对Minio的封装,简化使用 使用 appsetting.json "MinioOptions": { "Endpoint": "192.168.100.21:9000", "AccessKey": "admin", "SecretKey": "das@123!", "Region": "", "SessionToken": ""
}
services.AddMinio(options ⇒ { options.Endpoint = "endpoint"; // ... options.ConfigureClient(client ⇒ { client.WithSSL(); }); });
// Url based configuration services.AddMinio(new Uri("s3://accessKey:secretKey@localhost:9000/region"));
// Get or inject var client = serviceProvider.GetRequiredService<MinioClient>();
// Create new from factory var client = serviceProvider.GetRequiredService<IMinioClientFactory>().CreateClient(); ✅ Multiple clients support using named options
services.AddMinio(options ⇒ { options.Endpoint = "endpoint1"; // ... options.ConfigureClient(client ⇒ { client.WithSSL(); }); });
// Named extension overload services.AddMinio("minio2", options ⇒ { options.Endpoint = "endpoint2"; // ... options.ConfigureClient(client ⇒ { client.WithSSL().WithTimeout(...); }); });
// Explicit named Configure services.AddMinio() .Configure<MinioOptions>("minio3", options ⇒ { options.Endpoint = "endpoint3"; // ... });
// Get or inject first minio client var client = serviceProvider.GetRequiredService<MinioClient>();
// Create new minio2 var client = serviceProvider.GetRequiredService<IMinioClientFactory>().CreateClient("minio2");
// Create new minio3 var client = serviceProvider.GetRequiredService<IMinioClientFactory>().CreateClient("minio3");
public class MinioController : ControllerBase { private IServiceProvider serviceProvider;
public MinioController(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
[HttpPost]
public async Task<IActionResult> PutObjectAsync(IFormFile File,string key)
{
var minio = serviceProvider.GetRequiredService<MinioClient>();
var bucketName = "mymusic";
try
{
// Make a bucket on the server, if not already present.
var beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
bool found = await minio.BucketExistsAsync(beArgs).ConfigureAwait(false);
if (!found)
{
var mbArgs = new MakeBucketArgs()
.WithBucket(bucketName);
await minio.MakeBucketAsync(mbArgs).ConfigureAwait(false);
}
PolicyJson policyJson = new PolicyJson();
var args = new SetPolicyArgs()
.WithBucket(bucketName)
.WithPolicy(policyJson.SetPublic(bucketName));
await minio.SetPolicyAsync(args).ConfigureAwait(false);
var stream= File.OpenReadStream();
// Upload a file to bucket.
var putObjectArgs = new PutObjectArgs()
.WithBucket(bucketName)
.WithObject(key)
//.WithObject(File.FileName)
.WithContentType(File.ContentType)
.WithObjectSize(stream.Length)
.WithStreamData(stream);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
}
catch (Exception e)
{
Console.WriteLine("File Upload Error: {0}", e.Message);
}
return Ok(key);
}
[HttpGet]
public async Task<IActionResult> GetObjectAsync(string key) {
var minio = serviceProvider.GetRequiredService<MinioClient>();
var bucketName = "mymusic";
MemoryStream stream = new MemoryStream();
GetObjectArgs args = new GetObjectArgs().
WithBucket(bucketName).WithObject(key)
.WithCallbackStream(str=> {
str.CopyTo(stream);
});
var OBJ= await minio.GetObjectAsync(args);
stream.Position = 0;
return File(stream, "image/jpeg");
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- BorgNet.Startup (>= 1.0.0)
- Minio.AspNetCore (>= 4.0.5)
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 | 185 | 1/29/2023 |