FastDFS使用

public class FastdfsTest {
@Test
public void testUpload()throws Exception{
// 1、把FastDFS提供的jar包添加到工程中
// 2、初始化全局配置。加载一个配置文件。
ClientGlobal.init("C:\\Users\\Administrator\\Workspaces\\MyEclipse 10\\taotao-manager\\taotao-manager-web\\src\\main\\resources\\resource\\client.conf");
// 3、创建一个TrackerClient对象。
TrackerClient trackerClient = new TrackerClient();
// 4、创建一个TrackerServer对象。
TrackerServer trackerServer = trackerClient.getConnection();
// 5、声明一个StorageServer对象,null。
StorageServer storageServer = null;
// 6、获得StorageClient对象。
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
// 7、直接调用StorageClient对象方法上传文件即可。‪C:\Users\Administrator\Desktop\aaa.jpg C:\\Users\\Administrator\\Desktop\\aaa.jpg ‪C:/Users/Administrator/Desktop/aaa.jpg
String[] strings = storageClient.upload_file("\\C:\\Users\\Administrator\\Desktop\\aaa.jpg", "jpg", null);
for (String string : strings) {
System.out.println(string);
}

}
@Test
public void testDfsClient() throws Exception{
FastDFSClient fastDFSClient = new FastDFSClient("C:\\Users\\Administrator\\Workspaces\\MyEclipse 10\\taotao-manager\\taotao-manager-web\\src\\main\\resources\\resource\\client.conf");
String upString=fastDFSClient.uploadFile("\\C:\\Users\\Administrator\\Desktop\\aa.jpg", "jpg");
System.out.println(upString);
}
}

posted @ 2017-07-05 16:56  旋羽  阅读(308)  评论(0编辑  收藏  举报