1.导入依赖
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.7</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
2.yml配置文件
# 分布式文件系统FDFS配置
fdfs:
so-timeout: 1500
connect-timeout: 600
#缩略图生成参数
thumb-image:
width: 150
height: 150
#TrackerList参数,支持多个
tracker-list: 192.168.136.160:22122
web-server-url: http://192.168.136.160:8888/
3.测试用例
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AppServerApplication.class)
public class Test {//从调度服务器获取,一个目标存储服务器,上传
@Autowired
private FastFileStorageClient fastFileStorageClient;// 获取存储服务器的请求URL
@Autowired
private FdfsWebServer webServer;@Test
public void test() throws FileNotFoundException {
//1. 指定文件
File file = new File("F:\\a.jpg");
//2. 文件上传
StorePath path = client.uploadFile(new FileInputStream(file),
file.length(), "jpg", null);
//3. 拼接访问路径/*path.getFullPath()是指该文件所存放的路径信息和文件名,比如e/d/a.txt
webServer.getWebServerUrl()是指获取配置文件中的web-server-url */
String url = webServer.getWebServerUrl() + path.getFullPath();
}
}