Commit 4461671b authored by 黄奎's avatar 黄奎

文件下载修改

parent d622af05
......@@ -2146,10 +2146,8 @@ namespace Mall.WebApi.Controllers.TradePavilion
demodel.MallBaseId = RequestParm.MallBaseId;
demodel.TenantId = RequestParm.TenantId;
List<int> ExcelEnumIds = JsonConvert.DeserializeObject<List<int>>(parms.GetStringValue("ExcelEnumIds"));
string hashKey = Common.Config.GetHash(Common.Plugin.JsonHelper.Serialize(demodel));
string fileName = hashKey + ".xls";
string hashKey = Common.Config.GetHash(Common.Plugin.JsonHelper.Serialize(demodel) + parms.GetStringValue("ExcelEnumIds"));
string fileName = "品牌信息" + ".xls";
string filePath = Path.Combine(Directory.GetCurrentDirectory(), "upfile/temporary");
if (System.IO.Directory.Exists(filePath) == false)//如果不存在就创建file文件夹
{
......@@ -2169,8 +2167,11 @@ namespace Mall.WebApi.Controllers.TradePavilion
redisValue = redisHelper.StringGet(key);
if (string.IsNullOrEmpty(redisValue))
{
redisHelper.StringSet(key, fileName, TimeSpan.FromMinutes(30));
GetBrandListToExcel(demodel, ExcelEnumIds, tempPath, fileUrl);
redisHelper.StringSet(key, fileName, TimeSpan.FromMinutes(10));
Task.Run(() =>
{
GetBrandListToExcel(demodel, ExcelEnumIds, tempPath, fileUrl);
});
}
}
return await Task.Run<ApiResult>(() =>
......@@ -2227,16 +2228,15 @@ namespace Mall.WebApi.Controllers.TradePavilion
/// </summary>
/// <returns></returns>
[HttpPost]
public FileContentResult GetFile()
public async Task<FileContentResult> GetFile()
{
string ExcelName = "品牌列表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
JObject parms = JObject.Parse(RequestParm.msg.ToString());
string fileUrl = parms.GetStringValue("fileUrl");
string newPath = Directory.GetCurrentDirectory() + fileUrl;
if (System.IO.File.Exists(newPath))
{
byte[] fileBytes = System.IO.File.ReadAllBytes(newPath);
return File(fileBytes, "application/octet-stream", ExcelName);
var fileBytes = await System.IO.File.ReadAllBytesAsync(newPath);
return File(fileBytes, "application/octet-stream");
}
else
{
......@@ -2248,7 +2248,7 @@ namespace Mall.WebApi.Controllers.TradePavilion
/// 品牌下载
/// </summary>
private void GetBrandListToExcel(RB_Brand_Extend demodel, List<int> ExcelEnumIds,string filePath, string excelFileUrl)
private async void GetBrandListToExcel(RB_Brand_Extend demodel, List<int> ExcelEnumIds,string filePath, string excelFileUrl)
{
try
{
......
......@@ -24,10 +24,11 @@ namespace Mall.WebApi
webBuilder.ConfigureKestrel((context, options) =>
{
options.AllowSynchronousIO = true;
//设置应用服务器Kestrel请求体最大为50MB
options.Limits.MaxRequestBodySize = 52428800;
//设置应用服务器Kestrel请求体最大为100MB
options.Limits.MaxRequestBodySize = 104857600;
//解决并发异常
options.Limits.MinRequestBodyDataRate = null;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
});
webBuilder.UseStartup<Startup>().UseIIS();
});
......
......@@ -41,8 +41,13 @@ namespace Mall.WebApi
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true)
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x =>
{
x.AllowSynchronousIO = true;
x.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
})
.Configure<IISServerOptions>(x => { x.AllowSynchronousIO = true; })
;
services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文
......
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