| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System.ComponentModel.DataAnnotations; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | |
| | | namespace DocumentFile.Service.Controllers |
| | | { |
| | |
| | | _uploadService = uploadService; |
| | | } |
| | | |
| | | ///// <summary> |
| | | ///// 上传文件模板(doc、docx) |
| | | ///// </summary> |
| | | ///// <param name="code">租户唯一标识code</param> |
| | | ///// <param name="formFile">文件</param> |
| | | ///// <returns></returns> |
| | | //[HttpPost] |
| | | //public async Task<IActionResult> UploadDocTemplate([FromForm]string code,IFormFile formFile) |
| | | //{ |
| | | // ReturnMsg msg = new ReturnMsg(); |
| | | // if(formFile.Length>0) |
| | | // { |
| | | // msg = await this._uploadService.HandleUploadWordFile(formFile,code,""); |
| | | // } |
| | | // else |
| | | // { |
| | | // msg.error = "请上传文件"; |
| | | // } |
| | | |
| | | // return new JsonResult(msg); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 上传文件模板(doc、docx) |
| | | /// 上传文件(doc、docx) |
| | | /// 本地指定路径 |
| | | /// </summary> |
| | | /// <param name="code">租户唯一标识code</param> |
| | | /// <param name="formFile">文件</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<IActionResult> UploadDocTemplate([FromForm]string code,IFormFile formFile) |
| | | public async Task<IActionResult> UploadDocWithPath([FromForm]string code, [FromForm] string path, IFormFile formFile) |
| | | { |
| | | ReturnMsg msg = new ReturnMsg(); |
| | | if(formFile.Length>0) |
| | | if (formFile.Length > 0) |
| | | { |
| | | msg = await this._uploadService.HandleUploadTemplateFile(formFile,code); |
| | | msg = await this._uploadService.HandleUploadWordFile(formFile,code,path); |
| | | } |
| | | else |
| | | { |
| | |
| | | ReturnMsg msg = new ReturnMsg(); |
| | | if (formFile.Length > 0) |
| | | { |
| | | msg = await this._uploadService.HandleUploadWordFile(formFile, code); |
| | | msg = await this._uploadService.HandleUploadWordFile(formFile, code, ""); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除文件 |
| | | /// </summary> |
| | | /// <param name="delurl"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public IActionResult DeleteFile([FromForm] string[] delurl) |
| | | { |
| | | ReturnMsg msg = new ReturnMsg(); |
| | | try |
| | | { |
| | | if(delurl!=null && delurl.Length > 0) |
| | | { |
| | | var dir = AppDomain.CurrentDomain.BaseDirectory; |
| | | foreach (var item in delurl) |
| | | { |
| | | if (!string.IsNullOrEmpty(item)) |
| | | { |
| | | var path = dir + item; |
| | | if (System.IO.File.Exists(path)) |
| | | { |
| | | System.IO.File.Delete(path); |
| | | } |
| | | } |
| | | } |
| | | msg.code = 1; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | NLogProvider.GetInstance().Error(ex); |
| | | } |
| | | return new JsonResult(msg); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载文件 |
| | | /// </summary> |
| | | /// <param name="url"></param> |