using Bunny.Common.Connect; using Microsoft.AspNetCore.Http; using Minio; using Minio.DataModel.Args; using Minio.DataModel.Result; namespace Bunny.Service.IService.Service; public class MinioService : IMinioService { private readonly IMinioClient _minioContext = MinioContext.MinioClient!; /// /// 上传文件 /// /// 文件内容 public async void SaveMinioFile(IFormFile? file) { if (file == null) { Console.WriteLine("文件为空"); return; } var fileName = file.FileName; var contentType = file.ContentType; var putObjectResponse = await _minioContext.PutObjectAsync(new PutObjectArgs() .WithBucket(MinioContext.BucketName) .WithObject(fileName) .WithStreamData(file.OpenReadStream()) .WithContentType(contentType) .WithObjectSize(file.Length) ); Console.WriteLine($"putObjectResponse.ObjectNam---{putObjectResponse.ObjectName}"); } /// /// 查询所有的桶 /// /// 桶列表 public ListAllMyBucketsResult GetAllMyBuckets() { var listBucketsAsync = _minioContext!.ListBucketsAsync().Result; foreach (var bucket in listBucketsAsync.Buckets) { Console.WriteLine(bucket.Name); Console.WriteLine(bucket.CreationDate); Console.WriteLine(bucket.CreationDateDateTime); } return listBucketsAsync; } }