guohongjin
2024-05-01 1901fceb6ddaa56a57f3131191454554c3e77e68
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cn.stylefeng.guns.modular.business.controller; /**
 * @Project: fbwl
 * @Package cn.stylefeng.guns.modular.business.controller
 * @date 2023/5/15 23:20
 * @version V1.0
 */
 
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.utils.ObsUtil;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * @ClassName UploadController
 * @Description 上传控制类
 * @date 2023/5/15
 */
@RestController
@Api(tags = "文件上传类")
@ApiResource(name = "文件上传类", resBizType = ResBizTypeEnum.BUSINESS)
@RequestMapping("/business/upload")
public class UploadController {
 
    @Autowired
    private ObsUtil obsUtil;
 
    @ApiOperation("文件上传")
    @PostResource(name = "文件上传", path = "/uploadFile", requiredPermission = false)
    public ResponseData uploadFile(@RequestPart("file") MultipartFile file) {
        String url = obsUtil.upload(file);
        if (StrUtil.isEmpty(url)) {
            return new ErrorResponseData("文件上传失败");
        }
        return new SuccessResponseData(url);
    }
}