1. #配置文件

connect_timeout = 2

  1.  

network_timeout = 30

  1.  

charset = UTF-8

  1.  

http.tracker_http_port = 9090

  1.  

http.anti_steal_token = no

  1.  

http.secret_key = FastDFS1234567890

  1.  

tracker_server = 192.168.248.128:22122

  1.  

#tracker_server = 192.168.0.119:22122

  1.  
  1. package com.enation.newtest;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.junit.Test;
  6.  
  7. import java.io.FileNotFoundException;
  8. import java.io.FileOutputStream;
  9.  
  10. import java.util.UUID;
  11.  
  12. import org.apache.commons.io.IOUtils;
  13. import org.csource.common.MyException;
  14. import org.csource.common.NameValuePair;
  15. import org.csource.fastdfs.ClientGlobal;
  16. import org.csource.fastdfs.FileInfo;
  17. import org.csource.fastdfs.StorageClient;
  18. import org.csource.fastdfs.StorageClient1;
  19. import org.csource.fastdfs.StorageServer;
  20. import org.csource.fastdfs.TrackerClient;
  21. import org.csource.fastdfs.TrackerServer;
  22. import org.junit.After;
  23. import org.junit.Before;
  24.  
  25. public class TestFastDfs {
  26.  
  27. public String conf_filename = "E:\\fdfs_client.conf";
  28. //public String local_filename = "D:\\stsworkspace\\fastdfs-demo\\src\\main\\resources\\fdfs_client.conf";
  29.  
  30. public String local_filename = "E:\\2.jpg";
  31.  
  32. @Before
  33. public void setUp() throws Exception {
  34. }
  35.  
  36. @After
  37. public void tearDown() throws Exception {
  38. }
  39.  
  40. @Test
  41. public void testUpload() {
  42.  
  43. try {
  44. ClientGlobal.init(conf_filename);
  45.  
  46. TrackerClient tracker = new TrackerClient();
  47. TrackerServer trackerServer = tracker.getConnection();
  48. StorageServer storageServer = null;
  49. StorageClient1 client = new StorageClient1(trackerServer, storageServer);
  50.  
  51. StorageClient storageClient = new StorageClient(trackerServer, storageServer);
  52. // NameValuePair nvp = new NameValuePair("age", "18");
  53. NameValuePair nvp [] = new NameValuePair[]{
  54. new NameValuePair("age", "18"),
  55. new NameValuePair("sex", "male")
  56. };
  57. String fileIds[] = storageClient.upload_file(local_filename, "jpg", nvp);
  58.  
  59. System.out.println(fileIds.length);
  60. System.out.println("组名:" + fileIds[0]);
  61. System.out.println("路径: " + fileIds[1]);
  62.  
  63. } catch (FileNotFoundException e) {
  64. e.printStackTrace();
  65. } catch (IOException e) {
  66. e.printStackTrace();
  67. } catch (MyException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71.  
  72. @Test
  73. public void testDownload() {
  74. try {
  75.  
  76. ClientGlobal.init(conf_filename);
  77.  
  78. TrackerClient tracker = new TrackerClient();
  79. TrackerServer trackerServer = tracker.getConnection();
  80. StorageServer storageServer = null;
  81.  
  82. StorageClient storageClient = new StorageClient(trackerServer, storageServer);
  83. byte[] b = storageClient.download_file("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
  84. System.out.println(b);
  85. IOUtils.write(b, new FileOutputStream("D:/"+UUID.randomUUID().toString()+".conf"));
  86. } catch (Exception e) {
  87. e.printStackTrace();
  88. }
  89. }
  90.  
  91. @Test
  92. public void testGetFileInfo(){
  93. try {
  94. ClientGlobal.init(conf_filename);
  95.  
  96. TrackerClient tracker = new TrackerClient();
  97. TrackerServer trackerServer = tracker.getConnection();
  98. StorageServer storageServer = null;
  99.  
  100. StorageClient storageClient = new StorageClient(trackerServer, storageServer);
  101. FileInfo fi = storageClient.get_file_info("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
  102. System.out.println(fi.getSourceIpAddr());
  103. System.out.println(fi.getFileSize());
  104. System.out.println(fi.getCreateTimestamp());
  105. System.out.println(fi.getCrc32());
  106. } catch (Exception e) {
  107. e.printStackTrace();
  108. }
  109. }
  110.  
  111. @Test
  112. public void testGetFileMate(){
  113. try {
  114. ClientGlobal.init(conf_filename);
  115.  
  116. TrackerClient tracker = new TrackerClient();
  117. TrackerServer trackerServer = tracker.getConnection();
  118. StorageServer storageServer = null;
  119.  
  120. StorageClient storageClient = new StorageClient(trackerServer,
  121. storageServer);
  122. NameValuePair nvps [] = storageClient.get_metadata("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
  123. for(NameValuePair nvp : nvps){
  124. System.out.println(nvp.getName() + ":" + nvp.getValue());
  125. }
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. }
  129. }
  130.  
  131. @Test
  132. public void testDelete(){
  133. try {
  134. ClientGlobal.init(conf_filename);
  135.  
  136. TrackerClient tracker = new TrackerClient();
  137. TrackerServer trackerServer = tracker.getConnection();
  138. StorageServer storageServer = null;
  139.  
  140. StorageClient storageClient = new StorageClient(trackerServer,
  141. storageServer);
  142. int i = storageClient.delete_file("group1", "M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");
  143. System.out.println( i==0 ? "删除成功" : "删除失败:"+i);
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. }
  147. }
  148. }

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. js字节转换、字节格式化函数

    有时候在上传附件后需要显示大小,可以选择在后台处理,也可以在前台用js处理. 比如我们想1024MB转换成1GB,那就需要进行转换,这里只是介绍用js进行转换. function bytesToSiz ...

  2. http协议组成(请求状态码)

    http请求由:请求行:消息报头:请求正文组成 //请求行 Request URL: http://172.32.4.33:8080/operation/v2/autoServer/queryAuto ...

  3. 【jQuery】阶段(插入、复制、替换、删除)

    <p>你好!</p> 你最喜欢的水果是? <ul> <li title="苹果">苹果</li> <li titl ...

  4. C++基础 new和delete

    1.new delete 的使用 (1)基本数据类型 ); delete p; int *p = (int *)malloc(sizeof(int)); *p = ;free(p); (2)数组 ]; ...

  5. [BZOJ2243][SDOI2011]染色(树链剖分)

    [传送门] 树链剖分就行了,注意线段树上颜色的合并 Code #include <cstdio> #include <algorithm> #define N 100010 # ...

  6. Wireshark 的使用

    Wireshark 默认无法查看 https, 需要设置一下 新建环境变量 SSLKEYLOGFILE, 值为一个想要保存 sshKey 的文件, 如新建一个空文件 D:\AppData\SshKey ...

  7. getElementByName????????,????????,

    getElementByName可以获取多个元素,获得的是一个数组, getElementById只能获取一个,是dom从上往下的第一个元素.

  8. TP5 中出现 No input file specified

    之前用php5.4 更新至php7之后原tp5项目出现 No input file specified 修改方法: 打开public目录下的.htaccess文件,把:RewriteRule ^(.* ...

  9. MD5--3D模型

    在学习Away3D的过程中,接触到MD5模型和MD5动画这样两个词.之前对MD5的认识就是一种加密技术,怎么它又和动画扯上关系了呢. 一阵谷歌之后,终于在这个地方发现了关于3D方面的MD5介绍了:ht ...

  10. SQL Server 分组取 Top 笔记(row_number + over 实现)

    先看SQL语句(注意:这是在SQL Server 2005+ [包括2005] 的版本才支持的哦,o(∩_∩)o 哈哈~) SELECT col1,col2,col3 FROM table1 AS a ...