using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.ComponentModel.DataAnnotations; namespace DocumentFile.Service.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class DocumentController : ControllerBase { private readonly IUploadService _uploadService; /// /// 构造 /// /// public DocumentController(IUploadService uploadService) { _uploadService = uploadService; } /// /// 上传文件(word) /// /// [HttpPost] public async Task UploadDocument(IFormFile formFile) { ReturnMsg msg = new ReturnMsg(); if(formFile.Length>0) { msg = await this._uploadService.HandleUploadWordFile(formFile); } else { msg.error = "请上传文件"; } return new JsonResult(msg); } /// /// 下载文件 /// /// /// [HttpPost] public IActionResult Download([FromBody] string url) { try { if (!string.IsNullOrEmpty(url)) { var _webRootPath = AppDomain.CurrentDomain.BaseDirectory; return new FileStreamResult(new FileStream(_webRootPath + url, FileMode.Open), "application/octet-stream");// { FileDownloadName = FileName }; } } catch (Exception ex) { NLogProvider.GetInstance().Error(ex); } return BadRequest(); } } }