参考腾讯官方文档
pom
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.89</version>
</dependency>
application.yml
tencent:
cos:
accessKey: 你的秘钥id
secretKey: 你的秘钥
region: 你存储桶所在的区域
bucket: 你的存储桶名称
spring:
servlet:
multipart:
enabled: true
file-size-threshold: 5MB
max-file-size: 20MB
代码
- TencentCosProperties
@Data
@Component
@ConfigurationProperties(prefix = "tencent.cos")
public class TencentCosProperties {
private String accessKey;
private String secretKey;
private String region;
private String bucket;
}
- CosController
@RestController
public class CosController {
@Autowired
private TencentCosProperties tencentCosProperties;
@PostMapping