引入 oss-starter
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency>
配置key,endpoint相关信息
spring:
cloud:
alicloud:
access-key: xxxxxxxxx
secret-key: xxxxxxxxx
oss:
endpoint: xxxxxxxxxxxxxx
使用OSSClient 进行上传
@Autowired
private OSSClient ossClient;
@Test
public void upload(){
ossClient.putObject("pingmoweb","图片名.png",new File("C:\\图片.png"));
System.out.println("上传成功");
ossClient.shutdown();
}