Commit e630cea3bca6ec5c27e4da4591fdeb82d7e72fd7
Committed by
Gitee
!1093 【功能新增】Uni-App端文件直传到OSS服务
Merge pull request !1093 from 卢越/master-jdk17
Showing
1 changed file
with
17 additions
and
5 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/app/file/AppFileController.java
| @@ -2,19 +2,19 @@ package cn.iocoder.yudao.module.infra.controller.app.file; | @@ -2,19 +2,19 @@ package cn.iocoder.yudao.module.infra.controller.app.file; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.IoUtil; | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO; | ||
| 5 | import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO; | 7 | import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO; |
| 6 | import cn.iocoder.yudao.module.infra.service.file.FileService; | 8 | import cn.iocoder.yudao.module.infra.service.file.FileService; |
| 7 | import io.swagger.v3.oas.annotations.Operation; | 9 | import io.swagger.v3.oas.annotations.Operation; |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 11 | +import jakarta.annotation.Resource; | ||
| 12 | +import jakarta.validation.Valid; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.springframework.validation.annotation.Validated; | 14 | import org.springframework.validation.annotation.Validated; |
| 11 | -import org.springframework.web.bind.annotation.PostMapping; | ||
| 12 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | -import org.springframework.web.bind.annotation.RestController; | 15 | +import org.springframework.web.bind.annotation.*; |
| 14 | import org.springframework.web.multipart.MultipartFile; | 16 | import org.springframework.web.multipart.MultipartFile; |
| 15 | 17 | ||
| 16 | -import jakarta.annotation.Resource; | ||
| 17 | - | ||
| 18 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 18 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 19 | 19 | ||
| 20 | @Tag(name = "用户 App - 文件存储") | 20 | @Tag(name = "用户 App - 文件存储") |
| @@ -35,4 +35,16 @@ public class AppFileController { | @@ -35,4 +35,16 @@ public class AppFileController { | ||
| 35 | return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()))); | 35 | return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()))); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | + @GetMapping("/presigned-url") | ||
| 39 | + @Operation(summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器") | ||
| 40 | + public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(@RequestParam("path") String path) throws Exception { | ||
| 41 | + return success(fileService.getFilePresignedUrl(path)); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @PostMapping("/create") | ||
| 45 | + @Operation(summary = "创建文件", description = "模式二:前端上传文件:配合 presigned-url 接口,记录上传了上传的文件") | ||
| 46 | + public CommonResult<Long> createFile(@Valid @RequestBody FileCreateReqVO createReqVO) { | ||
| 47 | + return success(fileService.createFile(createReqVO)); | ||
| 48 | + } | ||
| 49 | + | ||
| 38 | } | 50 | } |