初次使用aliyun存储,进行网页图片查看 进入阿里云创建一个Bucket后保存好自己的ID与secrect然后用户设置权限为AliyunOSSFullAccess再去项目中进行环境变量的设置设置ID与secrect添加阿里云OSS依赖dependency groupIdcom.aliyun.oss/groupId artifactIdaliyun-sdk-oss/artifactId version3.17.4/version !-- 排除旧版 HttpClient避免与 Spring Boot 内置冲突 -- exclusions exclusion groupIdorg.apache.httpcomponents/groupId artifactIdhttpclient/artifactId /exclusion exclusion groupIdorg.apache.httpcomponents/groupId artifactIdhttpcore/artifactId /exclusion /exclusions /dependency我这个是 避免与springBoot的版本有冲突进行的排除准备完毕后进行代码测试在测试类中//文件上传测试 SpringBootTest class GulimallThridPartyApplicationTests { public static void main(String[] args) throws Exception { // 从环境变量获取 AccessKey[reference:4] EnvironmentVariableCredentialsProvider credentialsProvider CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider(); // 创建 OSSClient 实例[reference:5] OSS ossClient new OSSClientBuilder() .build(oss-cn-beijing.aliyuncs.com, credentialsProvider); try { // 构造上传请求[reference:6] PutObjectRequest putObjectRequest new PutObjectRequest( gulimall2026-7-5, // Bucket 名称 photo1.jpg, // 对象键 (Key) new File(C:\\Users\\64384\\Pictures\\Screenshots\\屏幕截图 2026-06-09 201706.png) // 本地文件路径 ); ossClient.putObject(putObjectRequest); System.out.println(Upload success!); } finally { ossClient.shutdown(); // 关闭客户端释放资源[reference:7] } } }运行代码完成后就可以到我们的bucket中去查看上传的图片