#配置文件

connect_timeout = 2


network_timeout = 30


charset = UTF-8


http.tracker_http_port = 9090


http.anti_steal_token = no


http.secret_key = FastDFS1234567890


tracker_server = 192.168.248.128:22122


#tracker_server = 192.168.0.119:22122

 
package com.enation.newtest;

import java.io.IOException;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.util.UUID; import org.apache.commons.io.IOUtils;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.FileInfo;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.junit.After;
import org.junit.Before; public class TestFastDfs { public String conf_filename = "E:\\fdfs_client.conf";
//public String local_filename = "D:\\stsworkspace\\fastdfs-demo\\src\\main\\resources\\fdfs_client.conf"; public String local_filename = "E:\\2.jpg"; @Before
public void setUp() throws Exception {
} @After
public void tearDown() throws Exception {
} @Test
public void testUpload() { try {
ClientGlobal.init(conf_filename); TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null;
StorageClient1 client = new StorageClient1(trackerServer, storageServer); StorageClient storageClient = new StorageClient(trackerServer, storageServer);
// NameValuePair nvp = new NameValuePair("age", "18");
NameValuePair nvp [] = new NameValuePair[]{
new NameValuePair("age", "18"),
new NameValuePair("sex", "male")
};
String fileIds[] = storageClient.upload_file(local_filename, "jpg", nvp); System.out.println(fileIds.length);
System.out.println("组名:" + fileIds[0]);
System.out.println("路径: " + fileIds[1]); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
} @Test
public void testDownload() {
try { ClientGlobal.init(conf_filename); TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null; StorageClient storageClient = new StorageClient(trackerServer, storageServer);
byte[] b = storageClient.download_file("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
System.out.println(b);
IOUtils.write(b, new FileOutputStream("D:/"+UUID.randomUUID().toString()+".conf"));
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void testGetFileInfo(){
try {
ClientGlobal.init(conf_filename); TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null; StorageClient storageClient = new StorageClient(trackerServer, storageServer);
FileInfo fi = storageClient.get_file_info("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
System.out.println(fi.getSourceIpAddr());
System.out.println(fi.getFileSize());
System.out.println(fi.getCreateTimestamp());
System.out.println(fi.getCrc32());
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void testGetFileMate(){
try {
ClientGlobal.init(conf_filename); TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null; StorageClient storageClient = new StorageClient(trackerServer,
storageServer);
NameValuePair nvps [] = storageClient.get_metadata("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
for(NameValuePair nvp : nvps){
System.out.println(nvp.getName() + ":" + nvp.getValue());
}
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void testDelete(){
try {
ClientGlobal.init(conf_filename); TrackerClient tracker = new TrackerClient();
TrackerServer trackerServer = tracker.getConnection();
StorageServer storageServer = null; StorageClient storageClient = new StorageClient(trackerServer,
storageServer);
int i = storageClient.delete_file("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
System.out.println( i==0 ? "删除成功" : "删除失败:"+i);
} catch (Exception e) {
e.printStackTrace();
}
}
}

FastDfs java客户端上传、删除文件的更多相关文章

  1. 【Web应用】JAVA网络上传大文件报500错误

    问题描述 当通过 JAVA 网站上传大文件,会报 500 错误. 问题分析 因为 Azure 的 Java 网站都是基于 IIS 转发的,所以我们需要关注 IIS 的文件上传限制以及 requestT ...

  2. hadoop(十)hdfs上传删除文件(完全分布式七)|12

    集群测试 上传小文件到集群,随便选择一个小文件上传到hdfs的根目录 [shaozhiqi@hadoop102 hadoop-3.1.2]$ bin/hdfs dfs -put wcinput/wc. ...

  3. Java 将要上传的文件上传至指定路径代码实现

    代码: /** * 上传文件到指定路径 * @param mFile 要上传的文件 * @param path 指定路径 */ public static void uploadFile(Multip ...

  4. Java Sftp上传下载文件

    需要使用jar包  jsch-0.1.50.jar sftp上传下载实现类 package com.bstek.transit.sftp; import java.io.File; import ja ...

  5. HttpClient由Client客户端上传File文件流至Server服务端

    客户端方法 public static void main(String[] args) { File file=new File("E:\\lucene\\rev\\全年平台受理量.doc ...

  6. 【Mac】之svn上传/删除文件命令

    创建文件后,进入文件夹下: ①先checkoutsvn地址: svn checkout https://xxxx:0000/svn/CM_B2B_Document/06_Testing/B2B_Ste ...

  7. windows上在linux客户端上传小文件lrzsz

    yum install lrzsz 即可 rz上传,会打开本地图形化界面直接上传 基于centos系统,其他系统请找对应 的源码包编译 一下

  8. window配置ftp服务,代码客户端上传下载文件

    1 开启ftp服务 打开控制面板,点击程序,找到程序和功能,点击”打开或关闭windows功能” 找到“Internet信息服务”,点击前面的加号,展开功能,勾选”FTP服务”,“FTP扩展性”,“I ...

  9. ceph rgw s3 java sdk 上传大文件分批的方法

    Using the AWS Java SDK for Multipart Upload (High-Level API) Topics Upload a File Abort Multipart Up ...

随机推荐

  1. GNU 汇编 协处理器指令

    1. CP15 协处理器 16组寄存器 mcr 写 mrc (rgeister CP15)  读 CP15 到 Register mrc  p15,0,c0,c0,0

  2. ethereum(以太坊)(十二)--应用(二)__投票(基础总和)

    编写应用合约之前,先弄清它的逻辑,有助于我们更好的部署合约 pragma solidity ^0.4.21; pragma experimental ABIEncoderV2; contract vo ...

  3. Orcale(一)

    oracle数据库基本语句查询 ORacle-12560:TNS 协议配置器错误 1.服务:1.监听服务未开启 2.服务器未开启 3.环境变量:Oracle_sid = orcl 4.regedit注 ...

  4. Python3.6+pyinstaller+Django

    方案(一)Python3.6+pyinstaller+windows服务 一.Python3.6(64位)环境清单 Django==1.11.7 django-windows-tools==0.2 P ...

  5. selenium破解极限

    一共分为两端段代码: 第一段:获取cookie 第二段:通过cookie登陆 这里以百度云为例: 第一部分:保存cookies,直接在cmd中执行就好 >>> from seleni ...

  6. JZOJ 5913. 林下风气

    Description 里口福因有林下风气,带领全国各地高校掀起了一股AK风,大家都十分痴迷于AK.里口福为了打击大家的自信心,出了一道自以为十分困难的题目.里口福有一棵树,第i个节点上有点权ai,他 ...

  7. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

  8. 1,MongoDB简介和安装

    一.初识MongoDB MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数 ...

  9. P2580 于是他错误的点名开始了(trie)

    P2580 于是他错误的点名开始了 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉 ...

  10. 二分查找iOS

    二分查找(也称折半查找)是很常见的一种在数组中查找数据的算法,作为一名程序员是应该必须会的.它的基础思想:获取数组的中间值,将数组分割成两份,利用查找的值跟中间值进行比较,如果查找的值大于中间值,就在 ...