Appearance
Cos对象存储
引用
java
@RestController
@Slf4j
@RequestMapping("/cos")
public class CosController {
...
@Resource
private CosService cosService;
...
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
文件上传
java
@PostMapping("/upload")
@Operation(summary = "文件上传")
public BaseResponse<String> upload(MultipartFile file, String biz) {
return cosService.uploadObject(file, biz);
}
1
2
3
4
5
2
3
4
5
文件下载到本地
java
@PostMapping("/downloadLocal")
@Operation(summary = "文件下载到本地")
public void downloadToLocal(String url, String localFilePath) {
cosService.download(url, localFilePath);
}
1
2
3
4
5
2
3
4
5
文件下载到流
java
@PostMapping("/download")
@Operation(summary = "文件下载到流")
public byte[] download(String url) throws IOException {
return cosService.getObject(url);
}
1
2
3
4
5
2
3
4
5
文件删除
java
@PostMapping("/delete")
@Operation(summary = "文件删除")
public BaseResponse<String> delete(String url) {
return cosService.deleteObject(url);
}
1
2
3
4
5
2
3
4
5
完整代码
java
@RestController
@Slf4j
@RequestMapping("/cos")
public class CosController {
@Resource
private CosService cosService;
@PostMapping("/upload")
@Operation(summary = "文件上传")
public BaseResponse<String> upload(MultipartFile file, String biz) {
return cosService.uploadObject(file, biz);
}
@PostMapping("/downloadLocal")
@Operation(summary = "文件下载到本地")
public void downloadToLocal(String url, String localFilePath) {
cosService.download(url, localFilePath);
}
@PostMapping("/download")
@Operation(summary = "文件下载到流")
public byte[] download(String url) throws IOException {
return cosService.getObject(url);
}
@PostMapping("/delete")
@Operation(summary = "文件删除")
public BaseResponse<String> delete(String url) {
return cosService.deleteObject(url);
}
}
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
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