This commit is contained in:
2025-10-14 14:01:09 +08:00
parent b053809142
commit 6a082ca162
28 changed files with 2368 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package com.fly;// package com.fly;
//
// import cn.hutool.core.date.DateTime;
// import cn.hutool.core.date.DateUtil;
// import cn.hutool.core.lang.UUID;
// import com.aliyun.oss.OSSClient;
// import com.aliyun.oss.model.CannedAccessControlList;
// import com.aliyun.oss.model.CreateBucketRequest;
// import com.aliyun.oss.model.PutObjectRequest;
// import com.aliyun.oss.model.PutObjectResult;
// import lombok.extern.slf4j.Slf4j;
// import org.junit.Test;
// <dependency>
// <groupId>com.aliyun.oss</groupId>
// <artifactId>aliyun-sdk-oss</artifactId>
// <version>3.17.4</version>
// </dependency>
// import java.io.File;
// // @SpringBootTest(classes = ZYPBootApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
// // @RunWith(SpringRunner.class)
// @Slf4j
// public class AliOssTest {
// @Test
// public void ossTest() {
// String bucketName = "zhiyoupiao";
// String endpoint = "oss-cn-wulanchabu.aliyuncs.com";
// String accessKeyId = "LTAI5tGePjTg9pYdQoQNpsiv";
// String secretAccessKey = "cb4VYWlZ95bg02n0MDu0JUpHEzik5A";
// File file = new File("d:\\Users\\jingh\\Pictures\\2024731yGhMRgzLIVEG.png");
// DateTime parse = DateUtil.parse("2025-11-08" + " 23:59:59");
// log.info("parse: {}", parse);
// // 创建OSSClient实例。
// OSSClient ossClient = new OSSClient(endpoint, accessKeyId, secretAccessKey);
// try {
// // 判断容器是否存在,不存在就创建
// if (!ossClient.doesBucketExist(bucketName)) {
// ossClient.createBucket(bucketName);
// CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
// createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
// ossClient.createBucket(createBucketRequest);
// }
// // 设置权限(公开读)
// ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
// // 设置文件路径和名称
// String folderNamePath = "images/";
// String fileUrl = folderNamePath + (UUID.randomUUID().toString().replace("-", "") + "-" + file.getName());
// String url = "https://" + bucketName + "." + endpoint + "/" + fileUrl;
// // 上传文件
// PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, fileUrl, file));
// if (result != null) {
// log.info("------OSS文件上传成功------" + fileUrl);
// log.info("------OSS文件上传成功------" + url);
// }
// } catch (Exception oe) {
// log.error("------OSS error-----", oe);
// }
// }
// }