Commit e630cea3bca6ec5c27e4da4591fdeb82d7e72fd7

Authored by 芋道源码
Committed by Gitee
2 parents 220c000d a0aa6273

!1093 【功能新增】Uni-App端文件直传到OSS服务

Merge pull request !1093 from 卢越/master-jdk17
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 2  
3 3 import cn.hutool.core.io.IoUtil;
4 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 7 import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO;
6 8 import cn.iocoder.yudao.module.infra.service.file.FileService;
7 9 import io.swagger.v3.oas.annotations.Operation;
8 10 import io.swagger.v3.oas.annotations.tags.Tag;
  11 +import jakarta.annotation.Resource;
  12 +import jakarta.validation.Valid;
9 13 import lombok.extern.slf4j.Slf4j;
10 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 16 import org.springframework.web.multipart.MultipartFile;
15 17  
16   -import jakarta.annotation.Resource;
17   -
18 18 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
19 19  
20 20 @Tag(name = "用户 App - 文件存储")
... ... @@ -35,4 +35,16 @@ public class AppFileController {
35 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 }
... ...