FastDfs java客户端上传、删除文件
#配置文件
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客户端上传、删除文件的更多相关文章
- 【Web应用】JAVA网络上传大文件报500错误
问题描述 当通过 JAVA 网站上传大文件,会报 500 错误. 问题分析 因为 Azure 的 Java 网站都是基于 IIS 转发的,所以我们需要关注 IIS 的文件上传限制以及 requestT ...
- hadoop(十)hdfs上传删除文件(完全分布式七)|12
集群测试 上传小文件到集群,随便选择一个小文件上传到hdfs的根目录 [shaozhiqi@hadoop102 hadoop-3.1.2]$ bin/hdfs dfs -put wcinput/wc. ...
- Java 将要上传的文件上传至指定路径代码实现
代码: /** * 上传文件到指定路径 * @param mFile 要上传的文件 * @param path 指定路径 */ public static void uploadFile(Multip ...
- Java Sftp上传下载文件
需要使用jar包 jsch-0.1.50.jar sftp上传下载实现类 package com.bstek.transit.sftp; import java.io.File; import ja ...
- HttpClient由Client客户端上传File文件流至Server服务端
客户端方法 public static void main(String[] args) { File file=new File("E:\\lucene\\rev\\全年平台受理量.doc ...
- 【Mac】之svn上传/删除文件命令
创建文件后,进入文件夹下: ①先checkoutsvn地址: svn checkout https://xxxx:0000/svn/CM_B2B_Document/06_Testing/B2B_Ste ...
- windows上在linux客户端上传小文件lrzsz
yum install lrzsz 即可 rz上传,会打开本地图形化界面直接上传 基于centos系统,其他系统请找对应 的源码包编译 一下
- window配置ftp服务,代码客户端上传下载文件
1 开启ftp服务 打开控制面板,点击程序,找到程序和功能,点击”打开或关闭windows功能” 找到“Internet信息服务”,点击前面的加号,展开功能,勾选”FTP服务”,“FTP扩展性”,“I ...
- ceph rgw s3 java sdk 上传大文件分批的方法
Using the AWS Java SDK for Multipart Upload (High-Level API) Topics Upload a File Abort Multipart Up ...
随机推荐
- 命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是否缺少程序集引用?
在一个web项目中需要导出word打印,引用Microsoft.Office.Interop.Word后,在pages里使用正常,在app_code里新建类引用就报错. Report.cs里using ...
- iptables v1.3.5: multiple -d flags not allowed错误已解决
今天写了一条iptables的规则 iptables -t filter -A INPUT -s 192.168.192.0/24 -d 192.168.192.140 -p tcp -dport 2 ...
- C++基础 C++对类的管理——封装
1.封装 两层含义: (1)把事物的属性和方法结合成个整体. (2)对类的属性和方法进行访问控制,对不信的进行信息屏蔽. 2.访问控制 控制分为 类的内部,类的外部. public 修饰的成员,可在内 ...
- 菜鸟教程perl总结
数据类型有: 标量$, 数组@,哈希% 数组声明 : @hits = (25, 30, 40); 或者 @sites = qw/google taobao runoob/; 数组操作 pop, ...
- UCLOUD使用云主机
购买云主机后,购买弹性ip: 设置外网防火墙,浏览器否则无法访问服务器资源: 在云主机绑定自定义的防火墙: 使用ssh登录服务器: 一般centos自带apache,没有的话安装,具体教程百度: 安装 ...
- Android面试收集录 Android布局
1.请说出Android中的五种布局,并介绍作用? FrameLayout(堆栈布局),层叠方式显示,类似于PhotoShop上的层叠图层. LinearLayout(线性布局),将视图以水平或者垂直 ...
- TouTiao开源项目 分析笔记1
1.InitApp==>项目的入口Application 1.1.继承了MultiDexApplication 超过65K方法的APP,会遇到65535的错误.原因就是为了支持比较大型的APP而 ...
- js柱状图
<!doctype html><html lang="en"><head><script type="text/javascri ...
- hihocoder1014 : Trie树
#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助, ...
- 使用node构建一个自己的服务器
我们做本地服务器,经常会选择Apache.IIS或者Tomcat,当然这些最方便的算是Apache,几乎不需要配置,最多就是配置下端口,亦或者我们想不用localhost,改成其他也是可以的,只要去更 ...