上传&下载步骤
1、加载tracker server的配置文件地址,配置文件为tracker server(调度服务器)的地址;
2、初始化客户端全局信息ClientGlobal.init(String conf)
3、创建存储客户端StorageClient(存储服务器)
4、调用storageClient的upload_file()方法上传&下载
5、解析并获取上传结果,返回组名和文件的相对路径
示例:
@Test
public void upload() throws Exception{
//加载配置文件,产生该文件的绝对路径
String conf_filename = this.getClass()
.getResource("/fastdfs_client.conf").getPath();
//初始化客户端全局对象
ClientGlobal.init(conf_filename);
//创建存储客户端对象
StorageClient storageClient = new StorageClient();
//上传
String[] arr = storageClient.upload_file(“图片路径”,
“jpg”,null);
System.out.println(Arrays.toString(arr));
/** 下载文件 */
byte[] data = storageClient.download_file(Arrays.toString(arr));
System.out.println(data.length);
FileOutputStream fos = new FileOutputStream(new File(“输出路径”));
fos.write(data);
fos.flush();
fos.close();
}