提供下载文件接口
This commit is contained in:
@@ -119,7 +119,7 @@ namespace IRaCIS.Core.API.Controllers
|
||||
[HttpPost("CommonDocument/UploadCommonDoc/{fileType}/{moduleType}")]
|
||||
[DisableRequestSizeLimit]
|
||||
[DisableFormValueModelBinding]
|
||||
public async Task<IResponseOutput> UploadCommonDoc(string fileType,string moduleType)
|
||||
public async Task<IResponseOutput> UploadCommonDoc(string fileType, string moduleType)
|
||||
{
|
||||
var boundary = HeaderUtilities.RemoveQuotes(MediaTypeHeaderValue.Parse(Request.ContentType).Boundary).Value;
|
||||
|
||||
@@ -151,6 +151,34 @@ namespace IRaCIS.Core.API.Controllers
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet("CommonDocument/DownloadCommonDoc")]
|
||||
public async Task<IActionResult> DownloadCommonFile(string code, [FromServices] IRepository<CommonDocument> _commonDocumentRepository)
|
||||
{
|
||||
var doc = _commonDocumentRepository.AsQueryable(true).FirstOrDefault(t => t.Code == code);
|
||||
|
||||
if (doc==null)
|
||||
{
|
||||
throw new Exception("当前code 没要找到对应的文件");
|
||||
}
|
||||
|
||||
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName;
|
||||
|
||||
var filePath = Path.Combine(rootPath, doc.Path);
|
||||
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
throw new Exception("服务器本地不存在该路径文件");
|
||||
}
|
||||
|
||||
|
||||
var stream = System.IO.File.OpenRead(filePath);
|
||||
return File(stream, "application/octet-stream", Path.GetFileName(doc.Name));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void DealCommonStorePath(string fileType, string moduleType, string fileRealName, out string serverFilePath, out string relativePath)
|
||||
{
|
||||
var rootPath = Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\')).FullName;
|
||||
|
||||
Reference in New Issue
Block a user