From 80006c969e6037984c25f541bd0a78866551aef5 Mon Sep 17 00:00:00 2001 From: mazhicheng Date: Mon, 29 Jun 2020 20:05:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=90=8E=E7=9A=84accessUrl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/controller/BaseFileController.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java b/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java index 7754d26..6d9a942 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java @@ -111,11 +111,11 @@ public abstract class BaseFileController extends BaseController { String fileUid = S.newUuid(); String newFileName = fileUid + "." + ext; String storageFullPath = FileHelper.saveFile(file, newFileName); - UploadFile uploadFile = new UploadFile(); uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext); uploadFile.setRelObjType(entityClass.getSimpleName()).setStoragePath(storageFullPath); - + String accessUrl = buildAccessUrl(newFileName); + uploadFile.setAccessUrl(accessUrl); String description = getString("description"); uploadFile.setDescription(description); // 返回uploadFile对象 @@ -152,19 +152,18 @@ public abstract class BaseFileController extends BaseController { /** * 保存文件 * @param uploadFileFormDTO - * @param * @return * @throws Exception */ - protected UploadFile saveFile(UploadFileFormDTO uploadFileFormDTO) throws Exception{ + protected UploadFile saveFile(UploadFileFormDTO uploadFileFormDTO) throws Exception{ // 文件后缀 String originFileName = uploadFileFormDTO.getFile().getOriginalFilename(); String ext = FileHelper.getFileExtByName( uploadFileFormDTO.getFile().getOriginalFilename()); // 先保存文件 String fileUid = S.newUuid(); String newFileName = fileUid + "." + ext; - String storageFullPath = FileHelper.saveFile( uploadFileFormDTO.getFile(), newFileName); - String accessUrl = FileHelper.getRelativePath(newFileName); + String storageFullPath = FileHelper.saveFile(uploadFileFormDTO.getFile(), newFileName); + String accessUrl = buildAccessUrl(newFileName); UploadFile uploadFile = new UploadFile(); uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext); uploadFile.setRelObjType(uploadFileFormDTO.getRelObjType()) @@ -175,6 +174,15 @@ public abstract class BaseFileController extends BaseController { return uploadFile; } + /** + * 构建文件访问/下载的url + * @param newFileName + * @return + */ + protected String buildAccessUrl(String newFileName){ + return "/uploadFile/download/" + newFileName; + } + /** * 保存上传文件信息 * @param uploadFile