|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
|
|
|
|
import org.junit.jupiter.api.Disabled;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.validation.Validation;
|
|
|
|
|
|
|
|
|
@ -12,23 +13,23 @@ public class S3FileClientTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Disabled // MinIO,如果要集成测试,可以注释本行
|
|
|
|
|
public void testMinIO() throws Exception {
|
|
|
|
|
public void testMinIO(MultipartFile file) throws Exception {
|
|
|
|
|
S3FileClientConfig config = new S3FileClientConfig();
|
|
|
|
|
// 配置成你自己的
|
|
|
|
|
config.setAccessKey("admin");
|
|
|
|
|
config.setAccessSecret("password");
|
|
|
|
|
config.setBucket("yudaoyuanma");
|
|
|
|
|
config.setAccessKey("minioadmin");
|
|
|
|
|
config.setAccessSecret("minioadmin");
|
|
|
|
|
config.setBucket("ktg-mes");
|
|
|
|
|
config.setDomain(null);
|
|
|
|
|
// 默认 9000 endpoint
|
|
|
|
|
config.setEndpoint("http://127.0.0.1:9000");
|
|
|
|
|
config.setEndpoint("https://www.lyrfp.com");
|
|
|
|
|
|
|
|
|
|
// 执行上传
|
|
|
|
|
testExecuteUpload(config);
|
|
|
|
|
testExecuteUpload(config,file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Disabled // 阿里云 OSS,如果要集成测试,可以注释本行
|
|
|
|
|
public void testAliyun() throws Exception {
|
|
|
|
|
public void testAliyun(MultipartFile file) throws Exception {
|
|
|
|
|
S3FileClientConfig config = new S3FileClientConfig();
|
|
|
|
|
// 配置成你自己的
|
|
|
|
|
config.setAccessKey(System.getenv("ALIYUN_ACCESS_KEY"));
|
|
|
|
@ -39,12 +40,12 @@ public class S3FileClientTest {
|
|
|
|
|
config.setEndpoint("oss-cn-beijing.aliyuncs.com");
|
|
|
|
|
|
|
|
|
|
// 执行上传
|
|
|
|
|
testExecuteUpload(config);
|
|
|
|
|
testExecuteUpload(config,file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Disabled // 腾讯云 COS,如果要集成测试,可以注释本行
|
|
|
|
|
public void testQCloud() throws Exception {
|
|
|
|
|
public void testQCloud(MultipartFile file) throws Exception {
|
|
|
|
|
S3FileClientConfig config = new S3FileClientConfig();
|
|
|
|
|
// 配置成你自己的
|
|
|
|
|
config.setAccessKey(System.getenv("QCLOUD_ACCESS_KEY"));
|
|
|
|
@ -55,12 +56,12 @@ public class S3FileClientTest {
|
|
|
|
|
config.setEndpoint("cos.ap-shanghai.myqcloud.com");
|
|
|
|
|
|
|
|
|
|
// 执行上传
|
|
|
|
|
testExecuteUpload(config);
|
|
|
|
|
testExecuteUpload(config,file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Disabled // 七牛云存储,如果要集成测试,可以注释本行
|
|
|
|
|
public void testQiniu() throws Exception {
|
|
|
|
|
public void testQiniu(MultipartFile file) throws Exception {
|
|
|
|
|
S3FileClientConfig config = new S3FileClientConfig();
|
|
|
|
|
// 配置成你自己的
|
|
|
|
|
// config.setAccessKey(System.getenv("QINIU_ACCESS_KEY"));
|
|
|
|
@ -73,12 +74,12 @@ public class S3FileClientTest {
|
|
|
|
|
config.setEndpoint("s3-cn-south-1.qiniucs.com");
|
|
|
|
|
|
|
|
|
|
// 执行上传
|
|
|
|
|
testExecuteUpload(config);
|
|
|
|
|
testExecuteUpload(config,file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Disabled // 华为云存储,如果要集成测试,可以注释本行
|
|
|
|
|
public void testHuaweiCloud() throws Exception {
|
|
|
|
|
public void testHuaweiCloud(MultipartFile file) throws Exception {
|
|
|
|
|
S3FileClientConfig config = new S3FileClientConfig();
|
|
|
|
|
// 配置成你自己的
|
|
|
|
|
// config.setAccessKey(System.getenv("HUAWEI_CLOUD_ACCESS_KEY"));
|
|
|
|
@ -89,19 +90,19 @@ public class S3FileClientTest {
|
|
|
|
|
config.setEndpoint("obs.cn-east-3.myhuaweicloud.com");
|
|
|
|
|
|
|
|
|
|
// 执行上传
|
|
|
|
|
testExecuteUpload(config);
|
|
|
|
|
testExecuteUpload(config,file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testExecuteUpload(S3FileClientConfig config) throws Exception {
|
|
|
|
|
private String testExecuteUpload(S3FileClientConfig config,MultipartFile file) throws Exception {
|
|
|
|
|
// 校验配置
|
|
|
|
|
ValidationUtils.validate(Validation.buildDefaultValidatorFactory().getValidator(), config);
|
|
|
|
|
// 创建 Client
|
|
|
|
|
S3FileClient client = new S3FileClient(0L, config);
|
|
|
|
|
client.init();
|
|
|
|
|
// 上传文件
|
|
|
|
|
String path = IdUtil.fastSimpleUUID() + ".jpg";
|
|
|
|
|
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
|
|
|
|
String fullPath = client.upload(content, path, "image/jpeg");
|
|
|
|
|
String path = IdUtil.fastSimpleUUID() + ".xlsx";
|
|
|
|
|
// byte[] content = ResourceUtil.readBytes(file);
|
|
|
|
|
String fullPath = client.upload(file.getBytes(), path, "xlsx");
|
|
|
|
|
System.out.println("访问地址:" + fullPath);
|
|
|
|
|
// 读取文件
|
|
|
|
|
if (true) {
|
|
|
|
@ -112,6 +113,7 @@ public class S3FileClientTest {
|
|
|
|
|
if (false) {
|
|
|
|
|
client.delete(path);
|
|
|
|
|
}
|
|
|
|
|
return fullPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|