diff --git a/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs b/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs index 7929d64..1762be1 100644 --- a/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs +++ b/Code/src/MineTec.ProManager.Application/GalleryFiles/GalleryFilesAppService.cs @@ -2,11 +2,15 @@ using Abp.Application.Services.Dto; using Abp.Collections.Extensions; using Abp.Domain.Repositories; +using Microsoft.AspNetCore.Http; using MineTec.ProManager.Commd; using MineTec.ProManager.GalleryFiles.Dto; using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Threading.Tasks; +using System.Web; namespace MineTec.ProManager.GalleryFiles { @@ -127,5 +131,62 @@ namespace MineTec.ProManager.GalleryFiles } return result; } + + //单个文件上传 + public async Task UploadFilessss(IFormFile file) + { + if (file == null) + { + return "请先选择文件"; + } + string webRootPath = @"D:\UploadingFiles\"; // wwwroot 文件夹 + string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd")); + string dirPath = Path.Combine(webRootPath, uploadPath); + if (!Directory.Exists(dirPath)) + { + Directory.CreateDirectory(dirPath); + } + string fileExt = Path.GetExtension(file.FileName).Trim('.'); //文件扩展名,不含“.” + string newFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + fileExt; //随机生成新的文件名 + var filePath = Path.Combine(dirPath, newFileName); + + using (var stream = new FileStream(filePath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + var url = $@"\{uploadPath}\{newFileName}"; + return url; + } + + //多个文件上传 + public async Task UploadPhotoszzzzz(IFormFileCollection files) + { + long size = files.Sum(f => f.Length); + + string webRootPath = @"D:\UploadingFiles\"; // wwwroot 文件夹 + string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd")); + string fileFolder = Path.Combine(webRootPath, uploadPath); + + if (!Directory.Exists(fileFolder)) + Directory.CreateDirectory(fileFolder); + + foreach (var file in files) + { + if (file.Length > 0) + { + var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + + Path.GetExtension(file.FileName); + var filePath = Path.Combine(fileFolder, fileName); + + using (var stream = new FileStream(filePath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + } + } + + var url = $@"\{uploadPath}\11"; + return url; + } } } \ No newline at end of file diff --git a/Pages/page/Graphic/PatternManager/addPattern.html b/Pages/page/Graphic/PatternManager/addPattern.html index 2171d58..95fb0ce 100644 --- a/Pages/page/Graphic/PatternManager/addPattern.html +++ b/Pages/page/Graphic/PatternManager/addPattern.html @@ -322,7 +322,7 @@ //选完文件后不自动上传 upload.render({ elem: '#btn_annex', - url: 'https://httpbin.org/post', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。 + url: apiUrl + '/api/services/app/GalleryFiles/UploadPhotos', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。 auto: false, multiple: false, accept: 'file', //普通文件 @@ -345,9 +345,9 @@ //选完文件后不自动上传 upload.render({ elem: '#btn_card', - url: 'https://httpbin.org/post', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。 + url: apiUrl +'/api/services/app/GalleryFiles/UploadPhotoszzzzz', //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。 auto: false, - multiple: false, + multiple: true, accept: 'file', //普通文件 exts: 'pdf|jpg', //只允许上传pdf和jpg size: 102400, //限制文件大小,单位 KB