Commit 92ace031fe17017ae577cf2e7ca3979fae9ebe21
1 parent
3310b766
【修复】访问数据库存储的文件,path 多层级时,无法访问的问题
Showing
3 changed files
with
22 additions
and
15 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.file; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| ... | ... | @@ -13,7 +14,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; |
| 13 | 14 | import cn.iocoder.yudao.module.infra.service.file.FileService; |
| 14 | 15 | import io.swagger.annotations.Api; |
| 15 | 16 | import io.swagger.annotations.ApiImplicitParam; |
| 16 | -import io.swagger.annotations.ApiImplicitParams; | |
| 17 | 17 | import io.swagger.annotations.ApiOperation; |
| 18 | 18 | import lombok.extern.slf4j.Slf4j; |
| 19 | 19 | import org.springframework.http.HttpStatus; |
| ... | ... | @@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile; |
| 24 | 24 | |
| 25 | 25 | import javax.annotation.Resource; |
| 26 | 26 | import javax.annotation.security.PermitAll; |
| 27 | +import javax.servlet.http.HttpServletRequest; | |
| 27 | 28 | import javax.servlet.http.HttpServletResponse; |
| 28 | 29 | import javax.validation.Valid; |
| 29 | 30 | |
| ... | ... | @@ -57,16 +58,20 @@ public class FileController { |
| 57 | 58 | return success(true); |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | - @GetMapping("/{configId}/get/{path}") | |
| 61 | + @GetMapping("/{configId}/get/**") | |
| 61 | 62 | @PermitAll |
| 62 | 63 | @ApiOperation("下载文件") |
| 63 | - @ApiImplicitParams({ | |
| 64 | - @ApiImplicitParam(name = "configId", value = "配置编号", required = true, dataTypeClass = Long.class), | |
| 65 | - @ApiImplicitParam(name = "path", value = "文件路径", required = true, dataTypeClass = String.class) | |
| 66 | - }) | |
| 67 | - public void getFileContent(HttpServletResponse response, | |
| 68 | - @PathVariable("configId") Long configId, | |
| 69 | - @PathVariable("path") String path) throws Exception { | |
| 64 | + @ApiImplicitParam(name = "configId", value = "配置编号", required = true, dataTypeClass = Long.class) | |
| 65 | + public void getFileContent(HttpServletRequest request, | |
| 66 | + HttpServletResponse response, | |
| 67 | + @PathVariable("configId") Long configId) throws Exception { | |
| 68 | + // 获取请求的路径 | |
| 69 | + String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false); | |
| 70 | + if (StrUtil.isEmpty(path)) { | |
| 71 | + throw new IllegalArgumentException("结尾的 path 路径必须传递"); | |
| 72 | + } | |
| 73 | + | |
| 74 | + // 读取内容 | |
| 70 | 75 | byte[] content = fileService.getFileContent(configId, path); |
| 71 | 76 | if (content == null) { |
| 72 | 77 | log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -27,7 +27,7 @@ public class SecurityConfiguration { |
| 27 | 27 | .antMatchers("/swagger-resources/**").anonymous() |
| 28 | 28 | .antMatchers("/webjars/**").anonymous() |
| 29 | 29 | .antMatchers("/*/api-docs").anonymous(); |
| 30 | - //积木报表 | |
| 30 | + // 积木报表 | |
| 31 | 31 | registry.antMatchers("/jmreport/**").permitAll(); |
| 32 | 32 | // Spring Boot Actuator 的安全配置 |
| 33 | 33 | registry.antMatchers("/actuator").anonymous() |
| ... | ... | @@ -37,6 +37,8 @@ public class SecurityConfiguration { |
| 37 | 37 | // Spring Boot Admin Server 的安全配置 |
| 38 | 38 | registry.antMatchers(adminSeverContextPath).anonymous() |
| 39 | 39 | .antMatchers(adminSeverContextPath + "/**").anonymous(); |
| 40 | + // 文件读取 | |
| 41 | + registry.antMatchers(buildAdminApi("/infra/file/*/get/**")).permitAll(); | |
| 40 | 42 | } |
| 41 | 43 | |
| 42 | 44 | }; | ... | ... |
yudao-server/pom.xml
| ... | ... | @@ -68,11 +68,11 @@ |
| 68 | 68 | <!-- <version>${revision}</version>--> |
| 69 | 69 | <!-- </dependency>--> |
| 70 | 70 | <!-- 工作流 --> |
| 71 | - <dependency> | |
| 72 | - <groupId>cn.iocoder.boot</groupId> | |
| 73 | - <artifactId>yudao-module-bpm-biz</artifactId> | |
| 74 | - <version>${revision}</version> | |
| 75 | - </dependency> | |
| 71 | +<!-- <dependency>--> | |
| 72 | +<!-- <groupId>cn.iocoder.boot</groupId>--> | |
| 73 | +<!-- <artifactId>yudao-module-bpm-biz</artifactId>--> | |
| 74 | +<!-- <version>${revision}</version>--> | |
| 75 | +<!-- </dependency>--> | |
| 76 | 76 | <dependency> |
| 77 | 77 | <groupId>cn.iocoder.boot</groupId> |
| 78 | 78 | <artifactId>yudao-spring-boot-starter-biz-error-code</artifactId> | ... | ... |