fastDFS的入门程序

导入jar包
<dependency>
            <groupId>cn.bestwu</groupId>
            <artifactId>fastdfs-client-java</artifactId>
            <version>1.27</version>
 </dependency>
配置文件只需要修改主机
# connect timeout in seconds
# default value is 30s
connect_timeout=30

# network timeout in seconds
# default value
is 30s
network_timeout=60
# the base path to store log files
base_path=/home/fastdfs

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=192.168.200.128:22122


#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

# if use connection pool
# default value is false
# since V4.05
use_connection_pool = false

# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600

# if load FastDFS parameters from tracker server
# since V4.05
# default value is false
load_fdfs_parameters_from_tracker=false

# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V4.05
use_storage_id = false

# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V4.05
storage_ids_filename = storage_ids.conf


#HTTP settings
http.tracker_server_port=80

#use "#include" directive to include HTTP other settiongs
##include http.conf
测试步骤
1. 加载配置文件
2. 创建管理端
3. 通过管理端获得连接
4. 创建存储端的对象
5. 上传文件
public class AppTest {
    public static void main(String[] args) throws IOException, MyException {
        //1. 加载配置文件
        ClientGlobal.init("E:\\Javafour\\ideaCode\\fastDFSDemo\\src\\main\\resources\\fdfs_client.conf");
        //2. 创建管理器
        TrackerClient trackerClient = new TrackerClient();
        //3. 通过管理端或的连接
        TrackerServer connection = trackerClient.getConnection();
        // 4. 创建存储端的对象
        StorageClient1 storageClient1 = new StorageClient1(connection,null);
        NameValuePair[] nameValuePairs = new NameValuePair[3];
        nameValuePairs[0]=new NameValuePair("fileName","dog");
        nameValuePairs[1]= new NameValuePair("extName","jpg");
        nameValuePairs[2] = new NameValuePair("author","jxy");
        //5. 上传文件
        String jpg = storageClient1.upload_file1("D:\\Desktop\\jxy\\pic\\dog.jpg", "jpg", nameValuePairs);
        System.out.println("--------"+jpg);

    }
}

 

posted @ 2019-11-18 15:20  小鱼儿&小于儿  阅读(160)  评论(0编辑  收藏  举报