diff --git a/IRaCIS.Core.Application/Helper/OSSService.cs b/IRaCIS.Core.Application/Helper/OSSService.cs index e935db222..4f7f12646 100644 --- a/IRaCIS.Core.Application/Helper/OSSService.cs +++ b/IRaCIS.Core.Application/Helper/OSSService.cs @@ -1,4 +1,4 @@ -using AlibabaCloud.SDK.Sts20150401; +using AlibabaCloud.SDK.Sts20150401; using Aliyun.OSS; using Aliyun.OSS.Common; using Amazon; @@ -529,40 +529,35 @@ public class OSSService : IOSSService { var minIOConfig = ObjectStoreServiceOptions.MinIO; - - var httpClientHandler = new HttpClientHandler - { - ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator - }; - var minioClient = new MinioClient() .WithEndpoint($"{minIOConfig.EndPoint}:{minIOConfig.Port}") .WithCredentials(minIOConfig.AccessKeyId, minIOConfig.SecretAccessKey) .WithSSL(minIOConfig.UseSSL) - .WithHttpClient(new HttpClient(httpClientHandler)) .Build(); var pipe = new System.IO.Pipelines.Pipe(); - var args = new GetObjectArgs() - .WithBucket(minIOConfig.BucketName) - .WithObject(ossRelativePath) - .WithCallbackStream(async stream => // ✅ 使用异步回调 + _ = Task.Run(async () => + { + try { - try - { - var pipeStream = pipe.Writer.AsStream(); - await stream.CopyToAsync(pipeStream); // ✅ 使用异步CopyTo - await pipe.Writer.CompleteAsync(); - } - catch (Exception ex) - { - Log.Error($"minio 获取流错误:{ex.Message}"); - await pipe.Writer.CompleteAsync(ex); - } - }); + var args = new GetObjectArgs() + .WithBucket(minIOConfig.BucketName) + .WithObject(ossRelativePath) + .WithCallbackStream(stream => + { + stream.CopyTo(pipe.Writer.AsStream()); + }); + + await minioClient.GetObjectAsync(args); + await pipe.Writer.CompleteAsync(); + } + catch (Exception ex) + { + await pipe.Writer.CompleteAsync(ex); + } + }); - await minioClient.GetObjectAsync(args); return pipe.Reader.AsStream(); #region 废弃2