😎数据导入直接用文件流模式解析,不生成临时文件
This commit is contained in:
parent
baaf18a2a8
commit
aac51ac1b1
@ -131,11 +131,19 @@ public class SysPosService : IDynamicApiController, ITransient
|
||||
[DisplayName("导入职位")]
|
||||
public async Task Import([Required] IFormFile file)
|
||||
{
|
||||
var tFile = await App.GetRequiredService<SysFileService>().UploadFile(new UploadFileInput { File = file });
|
||||
var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, tFile.FilePath, tFile.Id.ToString() + tFile.Suffix);
|
||||
using MemoryStream stream = new();
|
||||
await file.CopyToAsync(stream);
|
||||
|
||||
//var sysFileService = App.GetRequiredService<SysFileService>();
|
||||
//var tFile = await sysFileService.UploadFile(new UploadFileInput { File = file });
|
||||
//var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, tFile.FilePath, tFile.Id.ToString() + tFile.Suffix);
|
||||
|
||||
IImporter importer = new ExcelImporter();
|
||||
var res = await importer.Import<PosDto>(filePath);
|
||||
var res = await importer.Import<PosDto>(stream);
|
||||
|
||||
//// 删除上传的临时文件(避免文件冗余)
|
||||
//await sysFileService.DeleteFile(new BaseIdInput { Id = tFile.Id });
|
||||
|
||||
if (res == null || res.Exception != null)
|
||||
throw Oops.Oh(res.Exception);
|
||||
|
||||
|
||||
@ -271,6 +271,7 @@ const uploadFile = async () => {
|
||||
await getAPI(SysPosApi).apiSysPosImportPostForm(state.fileList[0].raw);
|
||||
handleQuery();
|
||||
ElMessage.success('上传成功');
|
||||
state.fileList = [];
|
||||
options.loading = false;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user