青羊经侦大队-数据平台
安瑾然
2022-07-12 77e4741346fb02d5a1f845b89f681a56d06dad0e
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
package com.example.jz.controller;
 
import com.example.jz.modle.R;
import com.example.jz.service.MinIOService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.IOException;
 
@RestController
@RequestMapping("/minio")
@Api(tags = "MinIO接口")
public class MinIOController {
    @Resource
    private MinIOService minIOService;
 
    @RequestMapping(method = RequestMethod.GET, value = "/getUrl")
    @ApiOperation("获取文件预览地址")
    public R<String> getUrl(@RequestParam String fileName) {
        return R.ok(minIOService.getPreviewFileUrl(fileName));
    }
 
    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public R<String> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        if (file.isEmpty()) {
            return R.failed("文件为空");
        }
        String fileName = minIOService.upload(file);
        return R.ok(fileName);
    }
}