fastdfs客户端
概述: 在开发中难免会用到文件存储,在众多的文件系统中个人对fastdfs情有独钟,但是鉴于
官方提供的java客户端及其的难使用,以及存在的线程安全性等问题,最终个人决定对fastdfs的java客户端
进行大面积的重构以方便使用,在此对fastdfs作者余庆表示万分感谢!
启动器远吗地址为: https://github.com/BruceAKABear/fastdfs-spring-boot-starter
<dependency>
<groupId>pro.dengyi</groupId>
<artifactId>fastdfs-client</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>pro.dengyi</groupId>
<artifactId>fastdfs-spring-boot-starter</artifactId>
<version>0.1</version>
</dependency>
//1.创建配置对象
FastdfsConfiguration fastdfsConfiguration = new FastdfsConfiguration();
//2.对配置对象进行设置
fastdfsConfiguration.setTrackers(new String[]{"192.168.199.2:22122", "192.168.199.3:22122"});
//3.创建操作模板对象,并将配置对象作为参数传入
FastdfsTemplate fastdfsTemplate = new FastdfsTemplate(fastdfsConfiguration);
//4.利用fasdfs模板对文件进行操作
TOP_LEFT:左上 TOP_CENTER:上中 TOP_RIGHT:右上
CENTER_LEFT:左中 CENTER:中中 CENTER_RIGHT:右中
BOTTOM_LEFT:左下 BOTTOM_CENTER:下中 BOTTOM_RIGHT:右下
1.1. 查询存储组
查询所有存储的基本信息
List<StorageGroupInfo> allStorageGroupInfo = fastdfsTemplate.getAllStorageGroupInfo();
1.2. 查询每个存储组下所有存储storage信息
查询制定group存储组下所有的存储服务器的基本信息
List<StorageInfo> allStorageInfo = fastdfsTemplate.doGetAllStorageInfo(groupName);
也可以通过指定groupName和存储服务器的ip查询指定的存储服务器的相关信息(但是文件会在同组内自行同步,那么查询单个
存储服务器将没什么意义)
1.3. 将存储服务器从存储服务器中删除
2.1. 系统初始化
2.1 查询所有存储服务器组信息
List<StorageGroupInfo> allStorageGroupInfo = fastdfsTemplate.getAllStorageGroupInfo();
2.2 查询组下所有所有存储服务器相关信息
List<StorageInfo> allStorageInfo = fastdfsTemplate.getAllStorageInfo(groupName);
2.3 文件上传
2.3.1 以文件字节数组的形式上传文件
String s = fastdfsTemplate.uploadFile(fileBytes, "112.jpg");
2.4 文件的删除