Commit 65a889f2 by xin.yang

some update

parent 0b92b558
...@@ -312,5 +312,51 @@ namespace Siger.ApiConfig.Controller ...@@ -312,5 +312,51 @@ namespace Siger.ApiConfig.Controller
return new ObjectResult(new { content = FileUtility.GetText(truePath) }); return new ObjectResult(new { content = FileUtility.GetText(truePath) });
} }
/// <summary>
/// 下载文件
/// </summary>
/// <returns></returns>
[HttpGet]
[NoResultFilter]
public IActionResult DownloadFileByUrl(string url, string name)
{
if (string.IsNullOrWhiteSpace(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 path = rootDir + url;
if (!System.IO.File.Exists(path))
{
return new NoContentResult();
}
try
{
var stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
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
};
return File(stream, "application/octet-stream");
}
catch
{
throw new BadRequestException(CommonEnum.Fail);
}
}
} }
} }
\ No newline at end of file
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