新版仿ok交易所-后端
zj
2025-01-06 6e21cf6973aa1898259ddceda665f0f1b06272ab
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
package com.yami.trading.api.controller;
 
 
import com.yami.trading.bean.model.FileUploadParamsModel;
import com.yami.trading.bean.vo.FileInfoVo;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.service.AwsS3OSSFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
 
@RestController
@Api(tags ="文件上传")
@RequestMapping("api")
public class ApiUploadFileController {
 
    @Autowired
    AwsS3OSSFileService awsS3OSSFileService;
 
    @PostMapping(value = "/api/uploadFile")
    @ApiOperation("文件上传")
    public Result uploadFile(FileUploadParamsModel model) {
        try {
            if (model.getFile().getSize() / 1000L > 4500) {
               throw  new YamiShopBindException("图片大小不能超过4M");
            }
            String path=  awsS3OSSFileService.uploadFile(model.getModuleName(), model.getFile());
            FileInfoVo fileInfoVo=new FileInfoVo();
            fileInfoVo.setHttpUrl(awsS3OSSFileService.getUrl(path));
            fileInfoVo.setPath(path);
            return Result.succeed(fileInfoVo);
        }
         catch (Exception e) {
             e.printStackTrace();
            throw  new YamiShopBindException("文件上传失败");
        }
    }
}