Commit 191ff74f by xin.yang

fix bug

parent 074e22d5
...@@ -3,6 +3,7 @@ using System.IO; ...@@ -3,6 +3,7 @@ using System.IO;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Web;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Siger.ApiCommon.Filters; using Siger.ApiCommon.Filters;
using Siger.ApiCommon.Utilities; using Siger.ApiCommon.Utilities;
...@@ -321,39 +322,32 @@ namespace Siger.ApiConfig.Controller ...@@ -321,39 +322,32 @@ namespace Siger.ApiConfig.Controller
[NoResultFilter] [NoResultFilter]
public IActionResult DownloadFileByUrl(string url, string name) public IActionResult DownloadFileByUrl(string url, string name)
{ {
if (string.IsNullOrWhiteSpace(url)) if (!string.IsNullOrEmpty(url))
{ {
return new NoContentResult(); var file_url = url.Split("Files");
} if (url.Length == 2)
var fileSetting = Config<FileSettings>.Get(); {
if (fileSetting == null) url = "Files" + file_url[1];
{ }
return new NoContentResult();
}
var rootDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileSetting.FileSetting.PhysicalFolder);
if (!Directory.Exists(rootDir))
{
return new NoContentResult();
} }
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, url).Replace("Files", "TemporaryFiles");
var path = rootDir + url;
if (!System.IO.File.Exists(path)) if (!System.IO.File.Exists(path))
{ {
return new NoContentResult(); return new NoContentResult();
} }
try try
{ {
var stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{ {
FileName = string.IsNullOrWhiteSpace(name) ? url.Substring(url.LastIndexOf('.')) : name FileName = name
}; };
return File(stream, "application/octet-stream"); return File(stream, "application/octet-stream");
} }
catch catch (Exception e)
{ {
throw new BadRequestException(CommonEnum.Fail); throw new BadRequestException(CommonEnum.Fail);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment