完善 yudao-spring-boot-starter-file 组件,支持 S3 对接云存储、local、ftp、sftp 等协议

This commit is contained in:
YunaiV
2022-03-14 22:09:41 +08:00
parent ed53ca3de9
commit 3d40fc81dd
15 changed files with 514 additions and 10 deletions

View File

@ -0,0 +1,39 @@
package cn.iocoder.yudao.framework.file.core.client.ftp;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.ftp.FtpMode;
import cn.iocoder.yudao.framework.file.core.client.impl.ftp.FtpFileClient;
import cn.iocoder.yudao.framework.file.core.client.impl.ftp.FtpFileClientConfig;
import org.junit.jupiter.api.Test;
public class FtpFileClientTest {
@Test
public void test() {
// 创建客户端
FtpFileClientConfig config = new FtpFileClientConfig();
config.setDomain("http://127.0.0.1:48080");
config.setBasePath("/home/ftp");
config.setHost("kanchai.club");
config.setPort(221);
config.setUsername("");
config.setPassword("");
config.setMode(FtpMode.Passive.name());
FtpFileClient client = new FtpFileClient(0L, config);
client.init();
// 上传文件
String path = IdUtil.fastSimpleUUID() + ".jpg";
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
String fullPath = client.upload(content, path);
System.out.println("访问地址:" + fullPath);
if (false) {
byte[] bytes = client.getContent(path);
System.out.println("文件内容:" + bytes);
}
if (false) {
client.delete(path);
}
}
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.framework.file.core.client.local;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.IdUtil;
import cn.iocoder.yudao.framework.file.core.client.impl.local.LocalFileClient;
import cn.iocoder.yudao.framework.file.core.client.impl.local.LocalFileClientConfig;
import org.junit.jupiter.api.Test;
public class LocalFileClientTest {
@Test
public void test() {
// 创建客户端
LocalFileClientConfig config = new LocalFileClientConfig();
config.setDomain("http://127.0.0.1:48080");
config.setBasePath("/Users/yunai/file_test");
LocalFileClient client = new LocalFileClient(0L, config);
client.init();
// 上传文件
String path = IdUtil.fastSimpleUUID() + ".jpg";
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
String fullPath = client.upload(content, path);
System.out.println("访问地址:" + fullPath);
client.delete(path);
}
}

View File

@ -76,6 +76,15 @@ public class S3FileClientTest {
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
String fullPath = client.upload(content, path);
System.out.println("访问地址:" + fullPath);
// 读取文件
if (false) {
byte[] bytes = client.getContent(path);
System.out.println("文件内容:" + bytes);
}
// 删除文件
if (false) {
client.delete(path);
}
}
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.framework.file.core.client.sftp;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.IdUtil;
import cn.iocoder.yudao.framework.file.core.client.impl.sftp.SftpFileClient;
import cn.iocoder.yudao.framework.file.core.client.impl.sftp.SftpFileClientConfig;
import org.junit.jupiter.api.Test;
public class SftpFileClientTest {
@Test
public void test() {
// 创建客户端
SftpFileClientConfig config = new SftpFileClientConfig();
config.setDomain("http://127.0.0.1:48080");
config.setBasePath("/home/ftp");
config.setHost("kanchai.club");
config.setPort(222);
config.setUsername("");
config.setPassword("");
SftpFileClient client = new SftpFileClient(0L, config);
client.init();
// 上传文件
String path = IdUtil.fastSimpleUUID() + ".jpg";
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
String fullPath = client.upload(content, path);
System.out.println("访问地址:" + fullPath);
if (false) {
byte[] bytes = client.getContent(path);
System.out.println("文件内容:" + bytes);
}
if (false) {
client.delete(path);
}
}
}