create-base-teek-theme
Version:
``` npm create base-teek-theme@latest my-first-blog ```
127 lines (89 loc) • 2.28 kB
Markdown
---
date: 2025-03-28 03:46:49
title: Cos对象存储
permalink: /pages/89cd20
top: 2
tags:
- Spring Boot
author:
name: 华总
link: https://xiaoying.org.cn
categories:
- 后端
- 功能扩展
- 通用模块
---
## 引用
```java
public class CosController {
...
private CosService cosService;
...
}
```
## 文件上传
```java
public BaseResponse<String> upload(MultipartFile file, String biz) {
return cosService.uploadObject(file, biz);
}
```
## 文件下载到本地
```java
public void downloadToLocal(String url, String localFilePath) {
cosService.download(url, localFilePath);
}
```
## 文件下载到流
```java
public byte[] download(String url) throws IOException {
return cosService.getObject(url);
}
```
## 文件删除
```java
public BaseResponse<String> delete(String url) {
return cosService.deleteObject(url);
}
```
## 完整代码
```java
public class CosController {
private CosService cosService;
public BaseResponse<String> upload(MultipartFile file, String biz) {
return cosService.uploadObject(file, biz);
}
public void downloadToLocal(String url, String localFilePath) {
cosService.download(url, localFilePath);
}
public byte[] download(String url) throws IOException {
return cosService.getObject(url);
}
public BaseResponse<String> delete(String url) {
return cosService.deleteObject(url);
}
}
```