编程语言
首页 > 编程语言> > 虚拟机上传文件测试类-java代码

虚拟机上传文件测试类-java代码

作者:互联网

package cn.kgc.test;


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

public class TestDFS {
    public static void main(String[] args) throws Exception {
        //1 读取配置文件
        ClientGlobal.init("H:\\IDEAL\\fastDFSDemo\\src\\main\\resources\\fdfs_client.conf");
        //2 创建管理端对象
        TrackerClient trackerClient = new TrackerClient();
        //3 通过管理端对象获得链接
        TrackerServer connection = trackerClient.getConnection();
        //4 创建 存储端文件‘
        StorageClient1 storageClient = new StorageClient1(connection,null);
        //创建文件属性信息数组
        NameValuePair[] meta_list=new NameValuePair[3];
        meta_list[0]=new NameValuePair("fileName","nannv");
        meta_list[1]=new NameValuePair("extName","jpg");
        meta_list[2]=new NameValuePair("zz","nan");
        //5上传文件
        String path = storageClient.upload_file1("H:\\img\\nan.jpg","jpg",meta_list);
        System.out.println(path);
    }


}

 控制台获得打印的地址后,将该地址拼接在http://192.168.200.128/的后面,即:http://192.168.200.128/group1/M00/00/01/wKjIgF2EPA6Aas1dAAHoJasCKC4296.jpg

 打开浏览器,通过地址访问上面地址就可以看到图片

 

标签:java,org,虚拟机,list,NameValuePair,meta,import,new,上传
来源: https://www.cnblogs.com/Hubert-dzl/p/11555645.html