This commit is contained in:
dev02 2022-11-11 10:14:04 +08:00
commit 0ac8b0a81f
3 changed files with 76 additions and 10 deletions

View File

@ -0,0 +1,64 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface;
using System;
using System.IO;
namespace FrontendWebApi.ApiControllers
{
public class FileController : MyBaseApiController<GraphManageController>
{
private readonly IBackendRepository backendRepository;
private readonly IFrontendRepository frontendRepository;
private string graphManageFileSaveAsPath = "";
private string operationFileSaveAsPath = "";
public FileController(IBackendRepository backendRepository, IFrontendRepository frontendRepository)
{
this.backendRepository = backendRepository;
this.frontendRepository = frontendRepository;
graphManageFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "graph_manage");
operationFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation");
}
public bool Download([FromQuery]string type , string savename, string oriname)
{
var path = "";
if (type == "graph")
{
path = Path.Combine(graphManageFileSaveAsPath, savename);
}
else if (type == "operation")
{
path = Path.Combine(operationFileSaveAsPath, savename);
}
if (System.IO.File.Exists(path) && path != "")
{
try
{
FileInfo xpath_file = new FileInfo(path); //要 using System.IO;
// 將傳入的檔名以 FileInfo 來進行解析(只以字串無法做)
HttpContext.Response.Clear(); //清除buffer
HttpContext.Response.ContentType = "application/octet-stream";
// 檔案類型還有下列幾種"application/pdf"、"application/vnd.ms-excel"、"text/xml"、"text/HTML"、"image/JPEG"、"image/GIF"
HttpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(oriname, System.Text.Encoding.UTF8));
// 考慮 utf-8 檔名問題,以 out_file 設定另存的檔名
HttpContext.Response.Headers.Add("Content-Length", xpath_file.Length.ToString()); //表頭加入檔案大小
HttpContext.Response.SendFileAsync(xpath_file.FullName);
return true;
}
catch (Exception)
{ return false; }
}
else
return false;
}
}
}

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System; using System;
using System.Linq; using System.Linq;
using System.Web;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface; using Repository.FrontendRepository.Interface;
using System.IO; using System.IO;
@ -232,14 +233,14 @@ namespace FrontendWebApi.ApiControllers
//原設計圖修改 //原設計圖修改
var new_guid = Guid.NewGuid(); var new_guid = Guid.NewGuid();
//刪除原本檔案 //刪除原本檔案
if (gm.oriSavName != null) if (gm.oriSavName != null && gii.oriOrgName == null)
{ {
FolderFunction folderFunction = new FolderFunction(); FolderFunction folderFunction = new FolderFunction();
folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.oriSavName)); folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.oriSavName));
} }
string fileName = null; string fileName = null;
if (gii.oriOrgName != null) if (gii.oriOrgName != null && gii.oriFile != null)
{ {
fileName = new_guid + "." + gii.oriOrgName.Split('.')[1]; fileName = new_guid + "." + gii.oriOrgName.Split('.')[1];
@ -257,13 +258,13 @@ namespace FrontendWebApi.ApiControllers
//竣工圖修改 //竣工圖修改
new_guid = Guid.NewGuid(); new_guid = Guid.NewGuid();
//刪除原本檔案 //刪除原本檔案
if (gm.donSavName != null) if (gm.donSavName != null && gii.donOrgName == null)
{ {
var folderFunction = new FolderFunction(); var folderFunction = new FolderFunction();
folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.donSavName)); folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.donSavName));
} }
if (gii.donOrgName != null) if (gii.donOrgName != null && gii.donFile != null)
{ {
fileName = new_guid + "." + gii.donOrgName.Split('.')[1]; fileName = new_guid + "." + gii.donOrgName.Split('.')[1];
@ -387,5 +388,6 @@ namespace FrontendWebApi.ApiControllers
return apiResult; return apiResult;
} }
} }
} }

View File

@ -7,8 +7,8 @@
} }
}, },
"JwtSettings": { "JwtSettings": {
"Issuer": "Admin", // "Issuer": "Admin", //<EFBFBD>o<EFBFBD>e<EFBFBD><EFBFBD>
"SignKey": "TaipeiDome123456", ////16 "SignKey": "TaipeiDome123456", //ñ<EFBFBD><EFBFBD>//<EFBFBD>̤<EFBFBD>16<EFBFBD>r<EFBFBD><EFBFBD>
"JwtLifeSeconds": 1800 "JwtLifeSeconds": 1800
}, },
"DBConfig": { "DBConfig": {