通用文档管理

This commit is contained in:
2022-03-31 14:09:34 +08:00
parent 6fa434f370
commit 7390b843b7
12 changed files with 654 additions and 336 deletions
@@ -111,6 +111,66 @@ namespace IRaCIS.Core.API.Controllers
return ResponseOutput.Ok();
}
/// <summary>
/// 上传通用文档 比如一致性核查的 比如导出的excel 模板
/// </summary>
/// <returns></returns>
[HttpPost("CommonDocument/UploadCommonDoc/{fileType}/{moduleType}")]
[DisableRequestSizeLimit]
[DisableFormValueModelBinding]
public async Task<IResponseOutput> UploadCommonDoc(string fileType,string moduleType)
{
var boundary = HeaderUtilities.RemoveQuotes(MediaTypeHeaderValue.Parse(Request.ContentType).Boundary).Value;
var reader = new MultipartReader(boundary, HttpContext.Request.Body);
var section = await reader.ReadNextSectionAsync();
while (section != null)
{
var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);
if (hasContentDispositionHeader)
{
DealCommonStorePath(fileType, moduleType, contentDisposition.FileName.Value, out string serverFilePath, out string relativePath);
await WriteFileAsync(section.Body, serverFilePath);
//仅仅返回一个文件,如果多文件上传 在最后返回多个路径
return ResponseOutput.Ok(new
{
FilePath = relativePath,
FullFilePath = relativePath + "?access_token=" + _userInfo.UserToken
});
}
section = await reader.ReadNextSectionAsync();
}
return ResponseOutput.Ok();
}
private void DealCommonStorePath(string fileType, string moduleType, string fileRealName, out string serverFilePath, out string relativePath)
{
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName;
//上传根路径
var _fileStorePath = Path.Combine(rootPath, StaticData.CommonFileFolder);
//文件类型路径处理
var uploadFolderPath = Path.Combine(_fileStorePath, moduleType, fileType);
if (!Directory.Exists(uploadFolderPath)) Directory.CreateDirectory(uploadFolderPath);
var fileNameEX = Path.GetExtension(fileRealName);
var trustedFileNameForFileStorage = Guid.NewGuid().ToString() + fileNameEX;
relativePath = $"/{StaticData.CommonFileFolder}/{moduleType}/{fileType}/{trustedFileNameForFileStorage}";
serverFilePath = Path.Combine(uploadFolderPath, trustedFileNameForFileStorage);
}
private void DealSysTemStorePath( string type, string fileRealName, out string serverFilePath, out string relativePath)
{
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName;
+6
View File
@@ -180,6 +180,12 @@
<param name="opt"></param>
<returns></returns>
</member>
<member name="M:IRaCIS.Core.API.Controllers.UploadController.UploadCommonDoc(System.String,System.String)">
<summary>
上传通用文档 比如一致性核查的 比如导出的excel 模板
</summary>
<returns></returns>
</member>
<member name="M:IRaCIS.Core.API.Controllers.UploadController.UploadVisitData(System.Guid,IRaCIS.Core.API.Controllers.UploadController.UploadFileTypeEnum,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.SubjectVisit})">
<summary>
上传临床数据