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 ...
随机推荐
- js字节转换、字节格式化函数
有时候在上传附件后需要显示大小,可以选择在后台处理,也可以在前台用js处理. 比如我们想1024MB转换成1GB,那就需要进行转换,这里只是介绍用js进行转换. function bytesToSiz ...
- http协议组成(请求状态码)
http请求由:请求行:消息报头:请求正文组成 //请求行 Request URL: http://172.32.4.33:8080/operation/v2/autoServer/queryAuto ...
- 【jQuery】阶段(插入、复制、替换、删除)
<p>你好!</p> 你最喜欢的水果是? <ul> <li title="苹果">苹果</li> <li titl ...
- C++基础 new和delete
1.new delete 的使用 (1)基本数据类型 ); delete p; int *p = (int *)malloc(sizeof(int)); *p = ;free(p); (2)数组 ]; ...
- [BZOJ2243][SDOI2011]染色(树链剖分)
[传送门] 树链剖分就行了,注意线段树上颜色的合并 Code #include <cstdio> #include <algorithm> #define N 100010 # ...
- Wireshark 的使用
Wireshark 默认无法查看 https, 需要设置一下 新建环境变量 SSLKEYLOGFILE, 值为一个想要保存 sshKey 的文件, 如新建一个空文件 D:\AppData\SshKey ...
- getElementByName????????,????????,
getElementByName可以获取多个元素,获得的是一个数组, getElementById只能获取一个,是dom从上往下的第一个元素.
- TP5 中出现 No input file specified
之前用php5.4 更新至php7之后原tp5项目出现 No input file specified 修改方法: 打开public目录下的.htaccess文件,把:RewriteRule ^(.* ...
- MD5--3D模型
在学习Away3D的过程中,接触到MD5模型和MD5动画这样两个词.之前对MD5的认识就是一种加密技术,怎么它又和动画扯上关系了呢. 一阵谷歌之后,终于在这个地方发现了关于3D方面的MD5介绍了:ht ...
- SQL Server 分组取 Top 笔记(row_number + over 实现)
先看SQL语句(注意:这是在SQL Server 2005+ [包括2005] 的版本才支持的哦,o(∩_∩)o 哈哈~) SELECT col1,col2,col3 FROM table1 AS a ...