文件上传功能优化

This commit is contained in:
陈淳
2022-10-12 14:43:35 +08:00
parent 4a54eb56a7
commit dd7bbb138a
72 changed files with 104 additions and 68 deletions

View File

@@ -31,7 +31,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public IActionResult Template()
{
List<T> users = new();
var fileName = nameof(T) + PathConst.DataTemplate;
var fileName = typeof(T).Name + PathConst.DataTemplate;
var path = ExcelHelper.DownloadImportTemplate(users, fileName, Path.Combine(PathConst.wwwroot, PathEnum.Excel.ToString()));
var file = System.IO.File.OpenRead(path);
return File(file, "text/plain", $"{DateTime.Now.ToString("yyyyMMddHHmmssffff") + fileName }.xlsx");

View File

@@ -116,7 +116,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
//落盘文件文件名为雪花id+自己的扩展名
string filename = data.Id.ToString() + Path.GetExtension(f.FileName);
using (var stream = new FileStream(Path.Combine($"{PathConst.wwwroot}/{type}", filename), FileMode.CreateNew, FileAccess.Write))
string typePath = $"{PathConst.wwwroot}/{type}";
if (!Directory.Exists(typePath))
{
Directory.CreateDirectory(typePath);
}
using (var stream = new FileStream(Path.Combine(typePath, filename), FileMode.CreateNew, FileAccess.Write))
{
await f.CopyToAsync(stream);
}