diff --git a/IRaCIS.Core.API/appsettings.Test_IRC.json b/IRaCIS.Core.API/appsettings.Test_IRC.json index 2ab92a091..e901a83e3 100644 --- a/IRaCIS.Core.API/appsettings.Test_IRC.json +++ b/IRaCIS.Core.API/appsettings.Test_IRC.json @@ -14,7 +14,7 @@ "ObjectStoreService": { - "ObjectStoreUse": "AliyunOSS", + "ObjectStoreUse": "AWS", "AliyunOSS": { "regionId": "cn-shanghai", @@ -34,6 +34,14 @@ "accessKey": "IDFkwEpWej0b4DtiuThL", "secretKey": "Lhuu83yMhVwu7c1SnjvGY6lq74jzpYqifK6Qtj4h", "bucketName": "test" + }, + + "AWS": { + "endpoint": "s3.us-east-1.amazonaws.com", + "useSSL": false, + "accessKey": "AKIAZQ3DRSOHFPJJ6FEU", + "secretKey": "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", + "bucketName": "ei-irc-test-store" } }, diff --git a/IRaCIS.Core.Application/Helper/OSSService.cs b/IRaCIS.Core.Application/Helper/OSSService.cs index 5f370b698..b8a86da4b 100644 --- a/IRaCIS.Core.Application/Helper/OSSService.cs +++ b/IRaCIS.Core.Application/Helper/OSSService.cs @@ -19,10 +19,15 @@ using SkiaSharp; namespace IRaCIS.Core.Application.Helper { - public class MinIOOptions + public class MinIOOptions: AWSOptions + { + public string port { get; set; } + + } + + public class AWSOptions { public string endpoint { get; set; } - public string port { get; set; } public bool useSSL { get; set; } public string accessKey { get; set; } public string secretKey { get; set; } @@ -51,6 +56,8 @@ namespace IRaCIS.Core.Application.Helper public AliyunOSSOptions AliyunOSS { get; set; } public MinIOOptions MinIO { get; set; } + public AWSOptions AWS { get; set; } + } public class ObjectStoreDTO @@ -154,6 +161,26 @@ namespace IRaCIS.Core.Application.Helper await minioClient.PutObjectAsync(putObjectArgs); } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS") + { + var minIOConfig = ObjectStoreServiceOptions.AWS; + + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endpoint}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var putObjectArgs = new PutObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithStreamData(memoryStream); + + await minioClient.PutObjectAsync(putObjectArgs); + } + else + { + throw new BusinessValidationFailedException("未定义的存储介质类型"); + } } @@ -203,7 +230,26 @@ namespace IRaCIS.Core.Application.Helper await minioClient.PutObjectAsync(putObjectArgs); } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS") + { + var minIOConfig = ObjectStoreServiceOptions.AWS; + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endpoint}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var putObjectArgs = new PutObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithFileName(localFilePath); + + await minioClient.PutObjectAsync(putObjectArgs); + } + else + { + throw new BusinessValidationFailedException("未定义的存储介质类型"); + } return "/" + ossRelativePath; } @@ -249,6 +295,25 @@ namespace IRaCIS.Core.Application.Helper await minioClient.GetObjectAsync(getObjectArgs); } + else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS") + { + var minIOConfig = ObjectStoreServiceOptions.AWS; + + var minioClient = new MinioClient().WithEndpoint($"{minIOConfig.endpoint}") + .WithCredentials(minIOConfig.accessKey, minIOConfig.secretKey).WithSSL(minIOConfig.useSSL) + .Build(); + + var getObjectArgs = new GetObjectArgs() + .WithBucket(minIOConfig.bucketName) + .WithObject(ossRelativePath) + .WithFile(localFilePath); + + await minioClient.GetObjectAsync(getObjectArgs); + } + else + { + throw new BusinessValidationFailedException("未定义的存储介质类型"); + } } catch (Exception ex) {