| | |
| | | { |
| | | public interface IUploadService |
| | | { |
| | | Task<ReturnMsg> HandleUploadWordFile(IFormFile iFormFile,string code); |
| | | Task<ReturnMsg> HandleUploadWordFile(IFormFile iFormFile,string code,string name); |
| | | |
| | | Task<ReturnMsg> HandleUploadTemplateFile(IFormFile iFormFile, string code); |
| | | //Task<ReturnMsg> HandleUploadTemplateFile(IFormFile iFormFile, string code); |
| | | |
| | | Task<ReturnMsg> HandleUploadImageFile(IFormFile iFormFile, string code); |
| | | |
| | |
| | | /// <param name="folder">文件夹分类标签</param> |
| | | /// <param name="format"></param> |
| | | /// <returns></returns> |
| | | protected async virtual Task<ReturnMsg> HandleUploadFile(IFormFile formFile,string tenant, string folder, params string[] format) |
| | | protected async virtual Task<ReturnMsg> HandleUploadFile(IFormFile formFile,string tenant, string folder,string name, params string[] format) |
| | | { |
| | | ReturnMsg msg = new ReturnMsg(); |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | var path = $"/uploads/{tenant}/{folder}/{DateTime.Now:yyyyMMdd}"; |
| | | var dir = this._webRootPath + path; |
| | | if (!Directory.Exists(dir)) |
| | | string path; |
| | | if (string.IsNullOrEmpty(name)) |
| | | { |
| | | Directory.CreateDirectory(dir); |
| | | //服务器命名 |
| | | path = $"/uploads/{tenant}/{folder}/{DateTime.Now:yyyyMMdd}"; |
| | | var dir = this._webRootPath + path; |
| | | if (!Directory.Exists(dir)) |
| | | { |
| | | Directory.CreateDirectory(dir); |
| | | } |
| | | var filename = CreateName(path, extensionName); |
| | | path +="/" + filename; |
| | | } |
| | | |
| | | var filename = CreateName(path,extensionName); |
| | | path += "/" + filename; |
| | | else |
| | | { |
| | | //本地上传命名 |
| | | path = name; |
| | | string baseDirectory = Path.GetDirectoryName(this._webRootPath + name); |
| | | if (!Directory.Exists(baseDirectory)) |
| | | { |
| | | Directory.CreateDirectory(baseDirectory); |
| | | } |
| | | } |
| | | |
| | | // 创建新文件 |
| | | using var fs = File.Create(this._webRootPath+ path); |
| | | using var fs = File.Create(this._webRootPath + path); |
| | | await formFile.CopyToAsync(fs); |
| | | // 清空缓冲区数据 |
| | | fs.Flush(); |
| | |
| | | /// <param name="iFormFile"></param> |
| | | /// <param name="format"></param> |
| | | /// <returns></returns> |
| | | public async virtual Task<ReturnMsg> HandleUploadWordFile(IFormFile iFormFile, string code) |
| | | => await this.HandleUploadFile(iFormFile,code, "Instance", ".doc",".docx"); |
| | | public async virtual Task<ReturnMsg> HandleUploadWordFile(IFormFile iFormFile, string code,string name) |
| | | => await this.HandleUploadFile(iFormFile,code, "Word",name, ".doc",".docx"); |
| | | |
| | | /// <summary> |
| | | /// 上传word模板文件 |
| | | /// </summary> |
| | | /// <param name="iFormFile"></param> |
| | | /// <param name="format"></param> |
| | | /// <returns></returns> |
| | | public async virtual Task<ReturnMsg> HandleUploadTemplateFile(IFormFile iFormFile, string code) |
| | | => await this.HandleUploadFile(iFormFile, code, "Template", ".doc", ".docx"); |
| | | ///// <summary> |
| | | ///// 上传word模板文件 |
| | | ///// </summary> |
| | | ///// <param name="iFormFile"></param> |
| | | ///// <param name="format"></param> |
| | | ///// <returns></returns> |
| | | //public async virtual Task<ReturnMsg> HandleUploadTemplateFile(IFormFile iFormFile, string code) |
| | | // => await this.HandleUploadFile(iFormFile, code, "Template", ".doc", ".docx"); |
| | | |
| | | /// <summary> |
| | | /// 上传图片 |
| | |
| | | /// <param name="folder"></param> |
| | | /// <returns></returns> |
| | | public async virtual Task<ReturnMsg> HandleUploadImageFile(IFormFile iFormFile, string code) |
| | | => await this.HandleUploadFile(iFormFile, code, "Photo", ".jpg", ".jpeg", ".png"); |
| | | => await this.HandleUploadFile(iFormFile, code, "Photo","", ".jpg", ".jpeg", ".png"); |
| | | /*, ".gif", ".jfif"*/ |
| | | |
| | | ///// <summary> |