fastFDS(第三篇)-fastFDS测试

fastFDS测试

非springboot整合jar包-fastdfs_client_v1.20地址:

https://download.csdn.net/download/weixin_38316697/12619623

首先准备一张测试图片:

fdfs_client.conf:

connect_timeout = 2
network_timeout = 30
charset = UTF-8
http.tracker_http_port = 8080
http.anti_steal_token = no
http.secret_key = FastDFS1234567890
tracker_server = 127.0.0.1:22122

上传例子:

  //上传文件
    @Test 
    public void testUpload() {    	
        try { 
            ClientGlobal.init(conf_filename); 
            TrackerClient tracker = new TrackerClient(); 
            TrackerServer trackerServer = tracker.getConnection(); 
            StorageServer storageServer = null; 

            StorageClient storageClient = new StorageClient(trackerServer, 
                    storageServer); 
            NameValuePair nvp [] = new NameValuePair[]{ 
                    new NameValuePair("item_id", "100010"), 
                    new NameValuePair("width", "80"),
                    new NameValuePair("height", "90")
            }; 
            String fileIds[] = storageClient.upload_file(local_filename, null, 
                    nvp); 
            System.out.println("组名:" + fileIds[0]); 
            System.out.println("路径: " + fileIds[1]); 

        } catch (FileNotFoundException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } catch (Exception e) {
			e.printStackTrace();
		}     	
    } 

效果:

下载例子:

	//客户端配置文件
	public String conf_filename = "F:\\fastdfsClient\\src\\cn\\itcast\\fastdfs\\cliennt\\fdfs_client.conf"; 
    //本地文件,要上传的文件
	public String local_filename = "F:\\image\\yangzhenyu.png"; 
    //下载文件
    @Test 
    public void testDownload() { 
        try {
            ClientGlobal.init(conf_filename); 
            TrackerClient tracker = new TrackerClient(); 
            TrackerServer trackerServer = tracker.getConnection(); 
            StorageServer storageServer = null; 
            StorageClient1 storageClient = new StorageClient1(trackerServer, storageServer);
            byte[] b = storageClient.download_file("group1", 
                    "M00/00/00/CjMgJV8OoLqAJMN0AAFo6gRUELQ074.png"); 
            if(b !=null){
                 saveFile(b, "F:\\image\\temp\\", UUID.randomUUID().toString()+".jpg"); 
            }
           
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 
    
    //将字节流写到磁盘生成文件
    private void saveFile(byte[] b, String path, String fileName) {  		
    	File file = new File(path+fileName);
    	FileOutputStream fileOutputStream = null;
    	try {
			fileOutputStream= new FileOutputStream(file);
			
			fileOutputStream.write(b);			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(fileOutputStream!=null){
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}			
		}		
  	}

效果:

  回到 fastFDS(第一篇)-分布式fastFDS集群介绍

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

栗子~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值