上一篇我们在docker中安装好了fastdfs,本篇就来上传一个图片进行测试
创建springboot项目,添加依赖
<dependency> <groupId>net.oschina.zcx7878</groupId> <artifactId>fastdfs-client-java</artifactId> <version>1.27.0.0</version> </dependency>
更改地址
书写测试类
@Test void contextLoads() throws IOException, MyException { ClientGlobal.initByProperties("fastdfs-client.properties"); TrackerClient trackerClient = new TrackerClient(); TrackerServer trackerServer = trackerClient.getConnection(); StorageServer storageServer=null; StorageClient1 client1 = new StorageClient1(trackerServer, storageServer); NameValuePair pairs[]=null; String fileId = client1.upload_file1("G:\\a.jpg", "jpg", pairs); System.out.println(fileId); }
运行后返回
查看文件
访问文件