From 6f9566f4d17b8ef76ac9fca0672f5e94886d74e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com> Date: Tue, 17 Jun 2025 10:15:05 +0800 Subject: [PATCH] =?UTF-8?q?1.=20minio=E6=B7=BB=E5=8A=A0=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AEmd5=E8=8E=B7=E5=8F=96=202.=20minio=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=B7=BB=E5=8A=A0md5=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/CloudSdk/minio/MinioService.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Infrastructure/CloudSdk/minio/MinioService.cs b/Infrastructure/CloudSdk/minio/MinioService.cs index b89021f..f979bbc 100644 --- a/Infrastructure/CloudSdk/minio/MinioService.cs +++ b/Infrastructure/CloudSdk/minio/MinioService.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Http; +using Infrastructure.Helpers; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Minio; using Minio.DataModel; @@ -53,6 +54,21 @@ public class MinioService } } + public async Task GetMetaObject(string objectName, string bucketName) + { + if (string.IsNullOrEmpty(bucketName)) + { + bucketName = _bucketName; + } + + var statArgs = new StatObjectArgs() + .WithBucket(bucketName) + .WithObject(objectName); + var meta = await _minioClient.StatObjectAsync(statArgs); + var md5 = meta.MetaData["md5"]; + return md5; // + } + public async Task EnsureBucketExistsAsync(string bucketName) { var existsArgs = new BucketExistsArgs().WithBucket(bucketName); @@ -165,11 +181,18 @@ public class MinioService using var stream = new MemoryStream(); await file.CopyToAsync(stream); stream.Position = 0; + var md5 = Md5.CalculateStreamMd5(stream); + stream.Position = 0; var putArgs = new PutObjectArgs() .WithBucket(bucketName) .WithObject(objectName) .WithStreamData(stream) .WithObjectSize(stream.Length) + .WithHeaders(new Dictionary() + { + //x-amz-meta-md5 + ["X-Amz-Meta-Md5"] = md5 + }) .WithContentType("application/octet-stream"); //.WithContentType(file.ContentType); await _minioClient.PutObjectAsync(putArgs);