龚焕茏
2024-03-05 a41b5ec59dce472385ad33094fb72691dad127ca
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
package org.dromara.demo.controller;
 
import io.minio.Result;
import org.dromara.common.core.domain.R;
import org.dromara.demo.util.MinioUtil;
import org.redisson.remote.ResponseEntry;
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.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.List;
 
@RestController
@RequestMapping("/file")
public class FileUploadController {
    @Autowired
    private MinioUtil minioUtil;
 
    @PostMapping("/img")
    public R<String> uploadMinio(@RequestPart MultipartFile[] file) throws Exception {
 
        /*//拿到图片  MultipartFile封装接受的类
        //拿到图片的名称
        String filename = file.getOriginalFilename();
        //拿到图片的 UUId + 图片类型 (解决图片重名的问题 )
        String uuid = UUID.randomUUID().toString();
        String imgType = filename.substring(filename.lastIndexOf("."));
        //图片文件的新名称 xxx/uuid.jpg   图片拼接后的名
        String fileName = uuid + imgType;*/
 
        List<String> uploads = minioUtil.uploads(file);
 
 
        return R.ok(uploads.toString());
    }
 
}