Commit 36da5d69b046fe1fdff34ca4487a13699516a6d0
1 parent
715c4257
1、增加 App 的文件上传接口
Showing
2 changed files
with
58 additions
and
0 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/app/file/AppFileController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.app.file; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.io.IoUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.infra.service.file.FileService; | ||
| 7 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 8 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 9 | +import lombok.extern.slf4j.Slf4j; | ||
| 10 | +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; | ||
| 14 | +import org.springframework.web.multipart.MultipartFile; | ||
| 15 | + | ||
| 16 | +import javax.annotation.Resource; | ||
| 17 | + | ||
| 18 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 19 | + | ||
| 20 | +@Tag(name = "用户 App - 文件存储") | ||
| 21 | +@RestController | ||
| 22 | +@RequestMapping("/infra/file") | ||
| 23 | +@Validated | ||
| 24 | +@Slf4j | ||
| 25 | +public class AppFileController { | ||
| 26 | + | ||
| 27 | + @Resource | ||
| 28 | + private FileService fileService; | ||
| 29 | + | ||
| 30 | + @PostMapping("/upload") | ||
| 31 | + @Operation(summary = "上传文件") | ||
| 32 | + public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception { | ||
| 33 | + MultipartFile file = uploadReqVO.getFile(); | ||
| 34 | + String path = uploadReqVO.getPath(); | ||
| 35 | + return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()))); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | +} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/app/file/vo/AppFileUploadReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.app.file.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | +import org.springframework.web.multipart.MultipartFile; | ||
| 6 | + | ||
| 7 | +import javax.validation.constraints.NotNull; | ||
| 8 | + | ||
| 9 | +@Schema(description = "用户 App - 上传文件 Request VO") | ||
| 10 | +@Data | ||
| 11 | +public class AppFileUploadReqVO { | ||
| 12 | + | ||
| 13 | + @Schema(description = "文件附件", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 14 | + @NotNull(message = "文件附件不能为空") | ||
| 15 | + private MultipartFile file; | ||
| 16 | + | ||
| 17 | + @Schema(description = "文件附件", example = "yudaoyuanma.png") | ||
| 18 | + private String path; | ||
| 19 | + | ||
| 20 | +} |