• 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);
    
        }
    }
    
  • 相关阅读:
    如何在 Linux 中更改 swappiness
    logrotate机制&原理
    Linux命令 – ln 软连接与硬链接区别介绍
    Python实现目录文件的全量和增量备份
    tr -d命令删除与字符无关的符号
    CentOS7搭建时间服务器-chrony
    linux(centos7.0以上版本)安装 mysql-5.7.24-linux-glibc2.12-x86_64.tar 版本的mysql
    运维相关指标数据采集并ES入仓
    Kubernetes容器集群管理环境
    C++调用IDL程序的做法(三)
  • 原文地址:https://www.cnblogs.com/xiaoyuer0506/p/11882313.html
Copyright © 2020-2023  润新知