diff --git a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs index b3e4cde44..c96d9b1c2 100644 --- a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs @@ -227,6 +227,8 @@ namespace IRaCIS.Core.API.Controllers _repository = repository; } + + [HttpPost, Route("Study/PreArchiveStudy")] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] public async Task PreArchiveStudy(PreArchiveStudyCommand preArchiveStudyCommand, @@ -262,6 +264,12 @@ namespace IRaCIS.Core.API.Controllers } + //public string UploadOOSTest(string filePath, string route) + //{ + + //} + + /// Dicom 归档 [HttpPost, Route("Study/ArchiveStudy")] [DisableFormValueModelBinding] diff --git a/IRaCIS.Core.API/appsettings.Development.json b/IRaCIS.Core.API/appsettings.Development.json index 17ea8a68d..076ddb95f 100644 --- a/IRaCIS.Core.API/appsettings.Development.json +++ b/IRaCIS.Core.API/appsettings.Development.json @@ -11,6 +11,13 @@ "Hangfire": "Server=123.56.94.154,1433\\MSSQLSERVER;Database=Hangfire_IRaCIS;User ID=sa;Password=dev123456DEV;TrustServerCertificate=true" }, + + "AliyunOSS": { + "endpoint": "https://zyypacs-code.oss-cn-shanghai.aliyuncs.com", + "accessKeyId": "mpXG7Nu6zTpsDrI1", + "accessKeySecret": "yNINcEb099SkNfF6vYKaoP8TZNI3xZ", + "bucketName": "zyypacs-code" + }, "BasicSystemConfig": { "OpenUserComplexPassword": false, diff --git a/IRaCIS.Core.Application/Helper/FileStoreHelper.cs b/IRaCIS.Core.Application/Helper/FileStoreHelper.cs index dbdd13cd4..0089d3e9a 100644 --- a/IRaCIS.Core.Application/Helper/FileStoreHelper.cs +++ b/IRaCIS.Core.Application/Helper/FileStoreHelper.cs @@ -1,10 +1,12 @@  +using Aliyun.OSS; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Newtonsoft.Json.Linq; +using System.Configuration; using System.Text.RegularExpressions; namespace IRaCIS.Core.Application.Helper; @@ -12,6 +14,39 @@ namespace IRaCIS.Core.Application.Helper; public static class FileStoreHelper { + public static string UploadOOS(string filePath,string route) + { + var endpoint = ConfigurationManager.AppSettings["AliyunOSS:endpoint"]; + // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。 + + // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。 + var accessKeyId = ConfigurationManager.AppSettings["AliyunOSS:accessKeyId"]; + var accessKeySecret = ConfigurationManager.AppSettings["AliyunOSS:accessKeySecret"]; + // 填写Bucket名称,例如examplebucket。 + var bucketName = ConfigurationManager.AppSettings["AliyunOSS:bucketName"]; + // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。 + + var fileNameList = filePath.Split(',').ToList(); + var fileName = fileNameList[fileNameList.Count() - 1]; + + var objectName = route+ fileName; + // 填写本地文件完整路径,例如D:\\localpath\\examplefile.txt。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。 + var localFilename = filePath; + // 创建OSSClient实例。 + var client = new OssClient(endpoint, accessKeyId, accessKeySecret); + try + { + // 上传文件。 + var result = client.PutObject(bucketName, objectName, localFilename); + + return result.ETag; + } + catch (Exception ex) + { + throw new BusinessValidationFailedException("上传异常!"); + + } + } //处理文件名 压缩包,或者目录类的 会带上相对路径 public static (string TrustedFileNameForFileStorage, string RealName) GetStoreFileName(string fileName,bool isChangeToPdfFormat=false) diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 656726dc8..247ed6016 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -63,6 +63,7 @@ +