#配置文件

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. 面向对象特性 - php

    1.类的字段调用格式 公用字段   类内调用 $this->字段名  类外调用 $对象名->字段名 静态  类内调用 self::$字段名   类外调用 类名::$字段名 常量 类内调用 ...

  2. PHP 多字节处理函数 mb_strlen

    一.前言 个人认为,PHP是世界上最好的语言.  二.介绍 查看yii2底层源码, 发现 mb_strlen($str, '8bit') , 此函数的不是PHP的核心函数, 所以需要开启对应的扩展.  ...

  3. css 自动换行,超出省略号代替

    overflow : hidden;    text-overflow: ellipsis;    display: -webkit-box;    -webkit-line-clamp: 2;    ...

  4. JavaScript通过HTML的class来获取HTML元素的方法总结

    对于js来说,我想每一个刚接触它的人都应该会抱怨:为什么没有一个通过class来获取元素的方法.尽管现在高版本的浏览器已经支持getElementsByClassName()函数,但是对于低版本浏览器 ...

  5. day1_作业2(三级菜单)--改进版

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- province={ '江苏省':{ '南京市':['秦淮区','玄武区','栖霞区'], '苏州市': ...

  6. python3 练习题100例 (十六)鸡尾酒疗法

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'Fan Lijun' n = input('请输入一个大于1,小于等于20的整 ...

  7. 数据结构学习-BST二叉查找树 : 插入、删除、中序遍历、前序遍历、后序遍历、广度遍历、绘图

    二叉查找树(Binary Search Tree) 是一种树形的存储数据的结构 如图所示,它具有的特点是: 1.具有一个根节点 2.每个节点可能有0.1.2个分支 3.对于某个节点,他的左分支小于自身 ...

  8. redis学习1(nosql)

    一. 互联网时代背景下大机遇,为什么用nosql 1.单机MySQL的美好年代 在90年代,一个网站的访问量一般都不大,用单个数据库完全可以轻松应付.在那个时候,更多的都是静态网页,动态交互类型的网站 ...

  9. [Luogu1341]无序字母对(欧拉回路)

    按题意给定字符串建无向图,找欧拉回路 按照定义,当没有奇数度点或者只有2个奇数度点时才有欧拉回路 Code #include <cstdio> #include <algorithm ...

  10. 18式优雅你的Python

    本文来自读者梁云同学的投稿,公众号:Python与算法之美 一,优雅你的Jupyter 1,更改Jupyter Notebook初始工作路径 平凡方法: 在cmd中输入jupyter notebook ...