Commit 191ff74f by xin.yang

fix bug

parent 074e22d5
......@@ -3,6 +3,7 @@ using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using Siger.ApiCommon.Filters;
using Siger.ApiCommon.Utilities;
......@@ -321,39 +322,32 @@ namespace Siger.ApiConfig.Controller
[NoResultFilter]
public IActionResult DownloadFileByUrl(string url, string name)
{
if (string.IsNullOrWhiteSpace(url))
if (!string.IsNullOrEmpty(url))
{
return new NoContentResult();
}
var fileSetting = Config<FileSettings>.Get();
if (fileSetting == null)
{
return new NoContentResult();
}
var rootDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileSetting.FileSetting.PhysicalFolder);
if (!Directory.Exists(rootDir))
{
return new NoContentResult();
var file_url = url.Split("Files");
if (url.Length == 2)
{
url = "Files" + file_url[1];
}
}
var path = rootDir + url;
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, url).Replace("Files", "TemporaryFiles");
if (!System.IO.File.Exists(path))
{
return new NoContentResult();
}
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) };
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = string.IsNullOrWhiteSpace(name) ? url.Substring(url.LastIndexOf('.')) : name
FileName = name
};
return File(stream, "application/octet-stream");
}
catch
catch (Exception e)
{
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