How do you do File Upload method in AppServices for aspnetboilerplate?

后端 未结 6 764
梦谈多话
梦谈多话 2021-01-14 11:17

I really like aspnetboilerplate framework, I learning/using it now..

How do you do \'File Upload\' logic/method in AppServices for aspnetboilerplate? The angular par

6条回答
  •  一个人的身影
    2021-01-14 11:35

    Create a file upload controller in the web.core project. Then reference your appService to process the file.

            [HttpPost]
            [AbpMvcAuthorize(PermissionNames.TenantPageJob)]
            public async Task UploadExcelJobs()
            {
                var files = Request.Form.Files;
                foreach (var file in files)
                {
                    if (file.Length > 0 && file.ContentType.Contains("excel"))
                    {
                        var targetPath = Path.Combine(Path.GetTempPath(), (new Guid().ToString()), file.FileName);
                        var fs = new FileStream(targetPath, FileMode.OpenOrCreate);
                        await file.CopyToAsync(fs);
                        await _myAppService.ProcessFile(targetPath);
                        System.IO.File.Delete(targetPath);
                    }
                }
            }
    

提交回复
热议问题