mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
1、增加 App 的文件上传接口
This commit is contained in:
parent
715c42574f
commit
36da5d69b0
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.yudao.module.infra.controller.app.file;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO;
|
||||||
|
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Tag(name = "用户 App - 文件存储")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/infra/file")
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
public class AppFileController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
|
@PostMapping("/upload")
|
||||||
|
@Operation(summary = "上传文件")
|
||||||
|
public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
|
||||||
|
MultipartFile file = uploadReqVO.getFile();
|
||||||
|
String path = uploadReqVO.getPath();
|
||||||
|
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package cn.iocoder.yudao.module.infra.controller.app.file.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Schema(description = "用户 App - 上传文件 Request VO")
|
||||||
|
@Data
|
||||||
|
public class AppFileUploadReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "文件附件", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "文件附件不能为空")
|
||||||
|
private MultipartFile file;
|
||||||
|
|
||||||
|
@Schema(description = "文件附件", example = "yudaoyuanma.png")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user