12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System.IO;
- using System.Threading.Tasks;
- using GxPress.Common.Exceptions;
- using GxPress.Common.Tools;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- namespace GxPress.Api.AdminControllers
- {
-
-
-
- [Route("api/admin/file")]
- [ApiController]
- public class AdminFileController : ControllerBase
- {
- private readonly IWebHostEnvironment _environment;
- public AdminFileController(IWebHostEnvironment environment)
- {
- _environment = environment;
- }
-
-
-
-
-
- [HttpPost("upload")]
- public async Task<ResultPath> Upload(IFormFile file)
- {
- if (file == null) throw new BusinessException("请选择需要上传的文件");
- byte[] bytes;
- await using (var ms = new MemoryStream())
- {
- file.CopyTo(ms);
- bytes = ms.ToArray();
- }
- var saveResult = FileHelper.SaveFile(StringUtils.GetWebRootPath(_environment.WebRootPath), file.FileName,
- bytes);
-
- saveResult.AbsolutePath = StringUtils.AddDomain(saveResult.RelativePath);
- return saveResult;
- }
-
-
-
-
-
-
-
- [HttpPost("upload-user-excel")]
- public async Task<ResultPath> UploadUserExcel(IFormFile file)
- {
- if (file == null) throw new BusinessException("请选择需要上传的文件");
- byte[] bytes;
- await using (var ms = new MemoryStream())
- {
- file.CopyTo(ms);
- bytes = ms.ToArray();
- }
- var saveResult = FileHelper.SaveFile(StringUtils.GetWebRootPath(_environment.WebRootPath), file.FileName,
- bytes);
-
- saveResult.AbsolutePath = StringUtils.AddDomain(saveResult.RelativePath);
- return saveResult;
- }
- }
- }
|