使用fastDFS上传和下载

package com.offcn;

import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;

public class controll {

    public static void main(String[] args) throws Exception {
        //加载配置文件(C:\Users\Thinkpad\IdeaProjects\fastDFS\src\main\resources\fdfs_client.conf"配置文件路径")
        ClientGlobal.init("C:\\Users\\Thinkpad\\IdeaProjects\\fastDFS\\src\\main\\resources\\fdfs_client.conf");
        //创建管理对象
        TrackerClient trackerClient = new TrackerClient();
        //通过管理对象获取连接
        TrackerServer connection = trackerClient.getConnection();
        //创建存储对象
        StorageClient1 client1 = new StorageClient1(connection, null);
        //上传文件
        NameValuePair[] pairs = new NameValuePair[3];
        pairs[0] = new NameValuePair("fileName", "jj");
        pairs[1]=new NameValuePair("ExtName","jpg");
        pairs[2]=new NameValuePair("zg","kk");
                                         //三个参数,第1个:是文件的路径       第2个文件的后缀名    第3个上传文件的信息
        String s = client1.upload_file1("D:\\Temp\\timg.jpg", "jpg", pairs);
        System.out.println(s);
    }



}

发布了33 篇原创文章 · 获赞 0 · 访问量 872

猜你喜欢

转载自blog.csdn.net/ninth_spring/article/details/103633537