首先要转一个FastDFS,这个很难装。一般由运维人员安装。

git项目fastdfs-client-java由happy fish开发的,down下来后import到项目中maven install到本地仓库即可

package com.common.utils;

import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;

/*
* 工具类
*/
public class FastDFSClient { private TrackerClient trackerClient = null;
private TrackerServer trackerServer = null;
private StorageServer storageServer = null;
private StorageClient1 storageClient = null; public FastDFSClient(String conf) throws Exception {
if (conf.contains("classpath:")) {
conf = conf.replace("classpath:", this.getClass().getResource("/").getPath());
}
ClientGlobal.init(conf);
trackerClient = new TrackerClient();
trackerServer = trackerClient.getConnection();
storageServer = null;
storageClient = new StorageClient1(trackerServer, storageServer);
} /**
* 上传文件方法
* <p>Title: uploadFile</p>
* <p>Description: </p>
* @param fileName 文件全路径
* @param extName 文件扩展名,不包含(.)
* @param metas 文件扩展信息
* @return
* @throws Exception
*/
public String uploadFile(String fileName, String extName, NameValuePair[] metas) throws Exception {
String result = storageClient.upload_file1(fileName, extName, metas);
return result;
} public String uploadFile(String fileName) throws Exception {
return uploadFile(fileName, null, null);
} public String uploadFile(String fileName, String extName) throws Exception {
return uploadFile(fileName, extName, null);
} /**
* 上传文件方法
* <p>Title: uploadFile</p>
* <p>Description: </p>
* @param fileContent 文件的内容,字节数组
* @param extName 文件扩展名
* @param metas 文件扩展信息
* @return
* @throws Exception
*/
public String uploadFile(byte[] fileContent, String extName, NameValuePair[] metas) throws Exception { String result = storageClient.upload_file1(fileContent, extName, metas);
return result;
} public String uploadFile(byte[] fileContent) throws Exception {
return uploadFile(fileContent, null, null);
} public String uploadFile(byte[] fileContent, String extName) throws Exception {
return uploadFile(fileContent, extName, null);
}
} /**
* 测试
*/
public class FastDFSTest {
@Test
public void testFileUpload() throws Exception {
// 1、加载配置文件,配置文件中的内容就是tracker服务的地址。
ClientGlobal.init("D:\\Programmer_QY\\eclipse-jee-mars-2-win32-x86_64\\workspace\\e3-manager-web\\src\\main\\resources\\conf\\client.conf");
// 2、创建一个TrackerClient对象。直接new一个。
TrackerClient trackerClient = new TrackerClient();
// 3、使用TrackerClient对象创建连接,获得一个TrackerServer对象。
TrackerServer trackerServer = trackerClient.getConnection();
// 4、创建一个StorageServer的引用,值为null
StorageServer storageServer = null;
// 5、创建一个StorageClient对象,需要两个参数TrackerServer对象、StorageServer的引用
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
// 6、使用StorageClient对象上传图片。
// 扩展名不带“.”
String[] strings = storageClient.upload_file("G:\\秋雨\\相机\\小猪\\QQ图片20160501233001.jpg", "jpg",
null);
// 7、返回数组。包含组名和图片的路径。
for (String string : strings) {
System.out.println(string);
}
}
@Test
public void textFastDfsClient() throws Exception{
FastDFSClient fastDFSClient = new FastDFSClient("D:\\Programmer_QY\\eclipse-jee-mars-2-win32-x86_64\\workspace\\e3-manager-web\\src\\main\\resources\\conf\\client.conf");
String result = fastDFSClient.uploadFile("G:\\秋雨\\相机\\头像\\3226-150PR30508-52.jpg");
System.out.println(result);
}
}

客户端返回

浏览器访问

FastDFS图片服务器的更多相关文章

  1. java连接Fastdfs图片服务器上传失败的解决方法

    照着视频上做,但是却连接不了虚拟机linux上的图片服务器,估计是linux防火墙的问题(这个实在是神烦,前面有好几次连接不了都是因为linux防火墙),果不其然,关闭即可. Linux关闭防火墙的命 ...

  2. FastDFS图片服务器搭建

    *FastDFS图片服务器搭建准备:1.需要libfastcommon安装包 选择最新稳定版(libfastcommon-1.0.36.tar.gz)2.需要FastDFS安装包 选择最新稳定版(fa ...

  3. FastDFS图片服务器(分布式文件系统)学习。

    参考:https://blog.csdn.net/hiqingtian/article/details/79413471 https://blog.csdn.net/sinat_40399893/ar ...

  4. [转帖]FastDFS图片服务器单机安装步骤

    FastDFS图片服务器单机安装步骤 https://www.cnblogs.com/yuesf/p/11847103.html 前面已经讲 一张图秒懂微服务的网络架构,通过此文章可以了解FastDF ...

  5. fastdfs 图片服务器 使用java端作为客户端上传图片

    之前有说道搭建fastdfs作为图片服务器,但是没有说明如何真正在代码里调用,那么今天大致讲一下,如何使用java客户端进行上传 首先你得要有一个客户端,导入到eclipse中即可 git地址如下: ...

  6. FastDFS图片服务器java后台的简单调用

    工具类: package com.liveyc.common.fdfs; import org.apache.commons.io.FilenameUtils; import org.csource. ...

  7. 分享知识-快乐自己:FastDFS 图片服务器的搭建

    使用一台虚拟机来模拟,只有一个Tracker.一个Storage服务,配置nginx访问图片. 1):安装依赖包 yum -y install zlib zlib-devel pcre pcre-de ...

  8. FastDFS图片服务器单机安装步骤

    前面已经讲 一张图秒懂微服务的网络架构,通过此文章可以了解FastDFS组件中单机安装流程. 单机版架构图 以下为单机FastDFS安装步骤 一.环境准备 CentOS 7.X libfastcomm ...

  9. FastDFS图片服务器单机安装步骤(修订版)

    前面已经讲 一张图秒懂微服务的网络架构,通过此文章可以了解FastDFS组件中单机安装流程. 单机版架构图 以下为单机FastDFS安装步骤 一.环境准备 CentOS 7.X libfastcomm ...

随机推荐

  1. 关于/proc/进程idpid/fd ,根据fd来查找连接

    当创建好epoll句柄后,它就是会占用一个fd值,在linux下如果查看/proc/进程id/fd/,是能够看到这个fd的,所以在使用完epoll后,必须调用close()关闭,否则可能导致fd被耗尽 ...

  2. 我与前端之间不得说的三天两夜之css基础

    前端基础之CSS CSS 语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. ''' selector { property: value; property: value; ... ...

  3. vue2+koa2+mongodb分页

    后端 const Koa = require('koa2'); const Router = require('koa-router'); const Monk = require('monk');/ ...

  4. 写入Csv

    //定义文件输出流  FILE *f; f = fopen("a.csv" , "wb"); fprintf(f,"aaa,23,sdf\n" ...

  5. 论文笔记:CNN经典结构1(AlexNet,ZFNet,OverFeat,VGG,GoogleNet,ResNet)

    前言 本文主要介绍2012-2015年的一些经典CNN结构,从AlexNet,ZFNet,OverFeat到VGG,GoogleNetv1-v4,ResNetv1-v2. 在论文笔记:CNN经典结构2 ...

  6. Python的进程、线程和threading模块

    (注:本文部分内容摘自互联网,由于作者水平有限,不足之处,还望留言指正.) 怀念在学校念书的时候,我不小心触碰到了错误,老师会说:你错了:而我却总是倔强得以为自己没错.我的内心是不屑的,直到在真理面前 ...

  7. sqlite常用的命令-增删改查

    一.查看版本信息: #sqlite3 -version 二.sqlite3常用命令 1.当前目录下建立或打开test.db数据库文件,并进入sqlite命令终端,以sqlite>前缀标识: 2. ...

  8. Ubuntu16.04中查看硬盘的型号和读取速度

    最近在测试FTP服务器,上传和下载的速度与很多因数有关,其中,硬盘的读取速度就是其中不同的区别点,我同时用了三台不用的服务器架设FTP服务,一台是出来ftp服务外还含平台其他管理软件,一台是全新的系统 ...

  9. MAC VNC SSH roo用户开通

    第一步:ssh: user@xxx.xxx.xxx 第二步:开启VNC 开启VNC共享桌面: sudo  /System/Library/CoreServices/RemoteManagement/A ...

  10. python之subprocess

    官网介绍:https://docs.python.org/3/library/subprocess.html Popen(): [root@oracle scripts]# cat sub_popen ...