提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.controller.app.file; |
H |
2 |
|
|
3 |
import cn.hutool.core.io.IoUtil; |
|
4 |
import com.iailab.framework.common.pojo.CommonResult; |
|
5 |
import com.iailab.module.infra.controller.app.file.vo.AppFileUploadReqVO; |
|
6 |
import com.iailab.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 com.iailab.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 |
} |