diff --git a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/Base64Utils.java b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/Base64Utils.java index 9229ed2..fb61c0d 100644 --- a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/Base64Utils.java +++ b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/Base64Utils.java @@ -47,6 +47,7 @@ public class Base64Utils { */ try { return new String(org.springframework.util.Base64Utils.decodeFromString(source.replaceAll(" ", "+").replaceAll("\n", "")), charsets); +// return new String(org.springframework.util.Base64Utils.decodeFromString(source.replaceAll(" ", "+").replaceAll("\n", "")), charsets); } catch (Exception e) { if (e.getMessage().toLowerCase().contains(BASE64_MSG)) { System.out.println("URL 解码异常,接入方法错误未使用 BASE64"); diff --git a/bonus-common/bonus-common-core/src/test/java/com/bonus/common/core/utils/Base64UtilsTest.java b/bonus-common/bonus-common-core/src/test/java/com/bonus/common/core/utils/Base64UtilsTest.java new file mode 100644 index 0000000..21e7ff9 --- /dev/null +++ b/bonus-common/bonus-common-core/src/test/java/com/bonus/common/core/utils/Base64UtilsTest.java @@ -0,0 +1,23 @@ +package com.bonus.common.core.utils; + +import org.junit.Test; + +import java.net.URLDecoder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class Base64UtilsTest { + + @Test + public void testDecodeUrl() { + String originString = "http://127.0.0.1:9300/statics/2024/10/30/网络拓扑图(6)_20241030171835A019.pdf"; + String decodeURL = "aHR0cDovLzEyNy4wLjAuMTo5MzAwL3N0YXRpY3MvMjAyNC8xMC8zMC%2FnvZHnu5zmi5PmiZHlm74oNilfMjAyNDEwMzAxNzE4MzVBMDE5LnBkZg%3D%3D"; + String decodeURL1 = "aHR0cDovLzEyNy4wLjAuMTo5MzAwL3N0YXRpY3MvMjAyNC8xMC8zMC/nvZHnu5zmi5PmiZHlm74oNilfMjAyNDEwMzAxNzE4MzVBMDE5LnBkZg=="; + String url = Base64Utils.decodeUrl( URLDecoder.decode(decodeURL)); + String url1 = Base64Utils.decodeUrl( URLDecoder.decode(decodeURL1)); + assertEquals(originString, url); + assertEquals(originString, url1); + } + +} diff --git a/bonus-modules/bonus-file/src/main/java/com/bonus/file/controller/SysFileController.java b/bonus-modules/bonus-file/src/main/java/com/bonus/file/controller/SysFileController.java index 6edb272..2a44e06 100644 --- a/bonus-modules/bonus-file/src/main/java/com/bonus/file/controller/SysFileController.java +++ b/bonus-modules/bonus-file/src/main/java/com/bonus/file/controller/SysFileController.java @@ -17,6 +17,8 @@ import com.bonus.system.api.domain.SysFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.net.URLDecoder; +import java.util.List; /** * 文件请求处理 @@ -81,7 +83,7 @@ public class SysFileController @GetMapping("/download") public void downloadFile(HttpServletResponse response, @RequestParam String objectKey) throws IOException { try { - String fileUrl = Base64Utils.decodeUrl(objectKey); + String fileUrl = Base64Utils.decodeUrl(URLDecoder.decode(objectKey)); sysFileService.downloadFile(response, fileUrl); } catch (Exception e) { log.error("downloadFile error:{}", e.getMessage()); @@ -104,11 +106,59 @@ public class SysFileController @DeleteMapping("/deleteFile") public AjaxResult deleteFile(@RequestParam("objectKey") String objectKey) { try { - String fileUrl = Base64Utils.decodeUrl(objectKey); + String fileUrl = Base64Utils.decodeUrl(URLDecoder.decode(objectKey)); sysFileService.deleteFile(fileUrl); } catch (Exception e) { return AjaxResult.error(e.getMessage()); } return AjaxResult.success("删除文件成功"); } + + /** + * 单文件上传到指定文件夹 + * @param file 单个文件 + * @return 文件信息,包括文件名和文件路径 + */ + @PostMapping("upload") + @ApiOperation("上传本地文件到服务器") + public AjaxResult upload(MultipartFile file, String folderName) + { + return AjaxResult.success("单文件上传成功"); + + } + + /** + * 创建文件夹 + * @param folderName 单个文件 + * @return 文件夹网络路径 + */ + @PostMapping("/createFolder") + @ApiOperation("创建文件夹") + public AjaxResult createFolder(@RequestParam("folderName") String folderName) + { + return AjaxResult.success("创建文件夹"); + } + + /** + * list 指定目录下所有文件信息(文件名,文件大小,上传时间,是否目录),包括子文件夹 + * @param folderName 文件夹名,默认为根目录 + * @return 文件夹网络路径 + */ + @GetMapping("/listFiles") + public AjaxResult listFiles(@RequestParam("folderName") String folderName) { + return AjaxResult.success("获取指定目录下所有文件成功"); + } + + + /** + * 文件夹删除 + * 从各个存储平台删除文件 + * @param folderName 文件夹名,默认为根目录 + * @return 文件夹网络路径 + */ + @DeleteMapping("/deleteFolder") + public AjaxResult deleteFolder(@RequestParam("folderName") String folderName) { + return AjaxResult.success("文件夹删除成功"); + } + } \ No newline at end of file