[Frontend][圖資管理] 下載dwg檔程序調整
This commit is contained in:
parent
7802738fa4
commit
e4a3cc9597
@ -139,6 +139,8 @@
|
||||
var uploader = {};
|
||||
var uploadFiles = {};
|
||||
var curActGraid = 0;
|
||||
var cookies = new YourTeam.Utility.Cookie();
|
||||
var token = cookies.get("JWT-Authorization");
|
||||
$(function () {
|
||||
initList();
|
||||
initDropzone();
|
||||
@ -283,19 +285,21 @@
|
||||
})
|
||||
|
||||
onEvent("click", "a[id^=oriDwgDown]", function () {
|
||||
let cookies = new YourTeam.Utility.Cookie();
|
||||
let rowData = graTable.row($(this).closest("tr")).data();
|
||||
let apiUrl = baseApiUrl + `/File/Download?type=graph&savename=${rowData.oriSavName}&oriname=${rowData.oriOrgName}`;
|
||||
let extname = rowData.oriOrgName?.split(".").slice(-1) || "dwg";
|
||||
download(cookies.get("JWT-Authorization"), apiUrl, rowData.name + "_原設計圖" + "." + extname);
|
||||
download(token, apiUrl, rowData.name + "_原設計圖" + "." + extname, function () {
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
onEvent("click", "a[id^=donDwgDown]", function () {
|
||||
let cookies = new YourTeam.Utility.Cookie();
|
||||
let rowData = graTable.row($(this).closest("tr")).data();
|
||||
let apiUrl = baseApiUrl + `/File/Download?type=graph&savename=${rowData.donSavName}&oriname=${rowData.donOrgName}`;
|
||||
let extname = rowData.donOrgName?.split(".").slice(-1) || "dwg";
|
||||
download(cookies.get("JWT-Authorization"), apiUrl, rowData.name + "_竣工圖" + "." + extname);
|
||||
download(token, apiUrl, rowData.name + "_竣工圖" + "." + extname, function () {
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
// 上傳檔案
|
||||
|
@ -2292,6 +2292,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
})
|
||||
|
||||
endPageLoading();
|
||||
$(".yt-alert").YTAlert().hide();
|
||||
|
||||
if (typeof timeOuters != "undefined") {
|
||||
$.each(timeOuters, (idx, timeOut) => {
|
||||
|
@ -1349,7 +1349,7 @@ function toBool(boolstr) {
|
||||
* @param {any} url
|
||||
* @param {any} filename
|
||||
*/
|
||||
async function download(token,url, filename) {
|
||||
async function download(token,url, filename,callback = null) {
|
||||
|
||||
let toDataURL = function (url) {
|
||||
return fetch(url, {
|
||||
@ -1378,6 +1378,7 @@ async function download(token,url, filename) {
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
callback ? callback() : "";
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -8,6 +8,10 @@ using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using NPOI.HPSF;
|
||||
|
||||
namespace FrontendWebApi.ApiControllers
|
||||
{
|
||||
@ -27,7 +31,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
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)
|
||||
public ActionResult Download([FromQuery]string type , string savename)
|
||||
{
|
||||
var path = "";
|
||||
if (type == "graph")
|
||||
@ -43,26 +47,27 @@ namespace FrontendWebApi.ApiControllers
|
||||
{
|
||||
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;
|
||||
var auth = HttpContext.Request.Headers["Authorization"];
|
||||
var token = auth.ToString()?.Split("Bearer ")[1];
|
||||
var jwt = new JwtSecurityTokenHandler().ReadJwtToken(token);
|
||||
if (jwt == null)
|
||||
return Unauthorized(HttpStatusCode.Unauthorized);
|
||||
else if (!System.IO.File.Exists(path))
|
||||
return NotFound("找不到文件");
|
||||
|
||||
var bufferingFeature = HttpContext.Features.Get<IHttpResponseBodyFeature>();
|
||||
bufferingFeature?.DisableBuffering();
|
||||
var content = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var response = File(content, "application/octet-stream");//FileStreamResult
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (Exception)
|
||||
{ return false; }
|
||||
{ return null; }
|
||||
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
Loading…
Reference in New Issue
Block a user