FileController.java
1.58 KB
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
48
49
50
51
package com.pashanhoo.common.util.fileupload;
import com.pashanhoo.common.Result;
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.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* 文件上传
*/
@Api(tags = "文件控制器")
@RequestMapping("/file")
@RestController
public class FileController {
@Autowired
MinioUtil minioUtil;
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ApiOperation("上传单个文件")
public Result upload(@RequestPart("file") MultipartFile file, HttpServletResponse response) {
try {
return Result.ok(minioUtil.upload(file));
} catch (Exception e) {
return Result.exception(e.getMessage());
}
}
@RequestMapping(value = "/batchUpload", method = RequestMethod.POST,headers = "content-type=multipart/form-data")
@ApiOperation("上传多个文件")
public Result upload(@RequestPart("file") MultipartFile[] files, HttpServletResponse response) {
try {
return Result.ok(minioUtil.batchUpload(files));
} catch (Exception e) {
return Result.exception(e.getMessage());
}
}
}