四、分布式ファイルシステムfastDFS-Java Api


四、分布式ファイルシステムfastDFS-Java Api
FastDFSはStorageClientによってアップロード操作を実行します
ソースコードを見ると、FastDFSには2つのStorageClientツールクラスがあることがわかります.
StorageClientのアップロード方法upload_file(...)は文字列配列String[]を返します.
例えば[group 1,M 00/00/wKgAb 1 dBK 2 iANrayAA 1 rIuRd 3 Es 112.jpg]
StorageClient 1のアップロード方法upload_file(...)は文字列Stringを返し、
例えばgroup 1/M 00/00/wKgAb 1 dBK 2 iANrayAA 1 rIuRd 3 Es 112.jpg、つまりもうつなぎ合わせてくれました
だからStorageClient 1のアップロード方法を使うのはもっと便利で、私たちが自分でつなぎ合わせる必要はありません.
public class FastDFSClient {
    private TrackerClient trackerClient = null;
    private TrackerServer trackerServer = null;
    private StorageServer storageServer = null;
    //  StorageClient1    
    private StorageClient1 storageClient1 = null;

    public FastDFSClient(String conf) throws Exception {
        //  classpath       "fdfs_client.conf"   
        //conf      classpath   ,    classpath:
        String configPath = this.getClass().getClassLoader().getResource(conf).getFile();
        System.out.println(configPath);
        ClientGlobal.init(configPath);

        trackerClient = new TrackerClient();
        trackerServer = trackerClient.getConnection();
        storageServer = trackerClient.getStoreStorage(trackerServer);
        storageClient1 = new StorageClient1(trackerServer, storageServer);
    }

   /**
      * MultipartFile picFile: file_buff = picFile.getBytes()
   */
    public String uploadFile(byte[] file_buff, String file_ext_name) throws Exception {
        String result = storageClient1.upload_file1(file_buff, file_ext_name, null);
        return result;
    }

    public String uploadFile(String local_filename, String file_ext_name) throws Exception {
        String result = storageClient1.upload_file1(local_filename, file_ext_name, null);
        return result;
    }

    //test
    public static void main(String[] args) throws Exception {
        FastDFSClient client = new FastDFSClient("properties/fdfs_client.conf");
        String result = client.uploadFile("C:\\Users\\Public\\Pictures\\Sample Pictures\\aaa.jpg", "jpg");
        System.out.println(result);
    }

}

原文:http://www.cnblogs.com/winner-0715/p/5516612.html