FastFDFS_Jave客戶端調用(親測可用)


 

 

一、配置文件(fdfs_client.properties)

1
2
3
4
5
6
7
8
9
10
connect_timeout = 30
network_timeout = 60
charset = ISO8859-1
# nginx 存儲器端口
http.tracker_http_port = 8888
http.anti_steal_token = no
http.secret_key = 123456
 
# 追蹤器服務端口
tracker_server = 192.168.146.131:22122

 

 

二、Java上傳跟圖片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.soa.test.fastdfs;
 
import org.csource.common.MyException;
import org.csource.fastdfs.*;
 
import java.io.IOException;
 
/**
  * Created by JamesC on 16-10-25.
  */
public class FastDfsTest {
 
 
     public static void main(String[] args) {
 
         uploadfile();
     }
 
 
     private static void uploadfile() {
         // 1、把FastDFS提供的jar包添加到工程中
         // 2、初始化全局配置。加載一個配置文件。
         try {
             ClientGlobal.init( "D:\\fdfs_client.properties" );
 
             // 3、創建一個TrackerClient對象。
             TrackerClient trackerClient = new TrackerClient();
             // 4、創建一個TrackerServer對象。
             TrackerServer trackerServer = null ;
 
             trackerServer = trackerClient.getConnection();
 
             // 5、聲明一個StorageServer對象,null。
             StorageServer storageServer = null ;
             // 6、獲得StorageClient對象。
             StorageClient storageClient = new StorageClient(trackerServer, storageServer);
             // 7、直接調用StorageClient對象方法上傳文件即可。
             String[] strings = storageClient.upload_file( "D:\\coupon.jpg" , "jpg" , null );
             for (String string : strings) {
                 System.out.println(string);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
}



三、下載路徑
1、調用storageClient.upload_file返回的文件地址:/M00/00/00/wKiSg1gPf8mAXoUFAACtqE-p50c210.jpg
2、完整下載地址:http://192.168.146.131:8888/group1/M00/00/00/wKiSg1gPf8mAXoUFAACtqE-p50c210.jpg

 

四、Java API客戶端jar包可從群里下載


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM