青羊经侦大队-数据平台
baizonghao
2023-03-23 0261d270c9f9b5282d923e585c307aee44b0612c
src/main/java/com/example/jz/controller/MinIOController.java
@@ -1,21 +1,35 @@
package com.example.jz.controller;
import com.example.jz.modle.R;
import com.example.jz.service.MinIOService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
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 = "/{fileName}")
    public String getUrl(@PathVariable String fileName){
        return "";
    @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);
    }
}