FastDFS简单入门小demo
图片上传
需要引入 FastDFS 相关的jar包,但是这个jar没有在中央仓库,所以还得需要找到这个jar手动安装到自己的本地仓库才能使用。
需要一个配置文件 fdfs_client.conf
需要一个 FastDFS 服务器
看代码:
fdfs_client.conf
# connect timeout in seconds
# default value is 30s
connect_timeout=30 # network timeout in seconds
# default value is 30s
network_timeout=60 # the base path to store log files
base_path=/home/fastdfs # tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.25.133:22122 #服务器地址 #standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info # if use connection pool
# default value is false
# since V4.05
use_connection_pool = false # connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
# since V4.05
connection_pool_max_idle_time = 3600 # if load FastDFS parameters from tracker server
# since V4.05
# default value is false
load_fdfs_parameters_from_tracker=false # if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V4.05
use_storage_id = false # specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V4.05
storage_ids_filename = storage_ids.conf #HTTP settings
http.tracker_server_port=80 #use "#include" directive to include HTTP other settiongs
##include http.conf
Test.java
package cn.itcast.demo; import java.io.FileNotFoundException;
import java.io.IOException; import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer; public class Test { public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
// 1.加载配置文件
ClientGlobal.init("D:\\pinyougou_bigdata1\\fastDFSdemo\\src\\main\\resources\\fdfs_client.conf");
// 2.构建一个管理者客户端
TrackerClient client=new TrackerClient();
// 3.连接管理者服务端
TrackerServer trackerServer = client.getConnection();
//4. 声明存储服务端
StorageServer storageServer=null;
//5. 获取存储服务器的客户端对象
StorageClient storageClient=new StorageClient(trackerServer, storageServer);
//6.上传文件
String[] strings = storageClient.upload_file("e:\\image\\b.jpg", "jpg", null);
//7.显示上传结果 file_id
for(String str:strings){
System.out.println(str);
} } }
FastDFS简单入门小demo的更多相关文章
- gulp安装+一个超简单入门小demo
gulp安装參考.gulp安装參考2. 一.NPM npm是node.js的包管理工具.主要功能是管理.更新.搜索.公布node的包. Gulp是通过npm安装的. 所以首先,须要安装node.js. ...
- angularJS入门小Demo【简单测试js代码的方法】
1.首先建立一个文件夹 demo, 2.在其中建立一个文本文档,改名为 demo-1.html, 3.把html中要引入的 js 文件拷贝到 demo目录下, 4.然后用 Notepadd++ 编辑刚 ...
- AngularJS - 入门小Demo
AngularJS四大特效 MVC模式.模块化设计.自动化双向数据绑定.依赖注入 如果了解了后端开发知识,想必对这些词汇不会陌生,AngularJS融合了后端开发的一些思想,虽然身为前端框架,但与jQ ...
- 基于vue-cli、elementUI的Vue超简单入门小例子
- 这个例子还是比较简单的,独立完成后,能大概知道vue是干嘛的,可以写个todoList的小例子. - 开始写例子之前,先对环境的部署做点简单的介绍,其实和Vue官方的差不多. #如若没有安装过vu ...
- spring boot简单的小demo(适合于初学者)
import com.example.demo2.com.example.dao.ShopDao; import com.example.demo2.com.example.entity.Shops; ...
- js 模仿jquery 写个简单的小demo
<div id="div" style="background:red;width:100px;height:300px"> 123123123 & ...
- js跨域请求jsonp解决方案-最简单的小demo
这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协议.域名.端口有任何一个不同,都被 ...
- 1.Django入门小Demo
1.Django安装 (1)前提:已安装python环境 (2)打开命令行输入:pip install Django==2.1.3 (3)打开Pycharm,在File--Setting--Proje ...
- Spring Data Solr入门小Demo
package com.offcn.pojo; import java.io.Serializable; import java.math.BigDecimal; import java.util.D ...
随机推荐
- [LOJ#6198]谢特[后缀数组+trie+并查集]
题意 给你一个长度为 \(n\) 的字符串,问 \(LCP(i,j)+(w_i\ xor\ w_j)\) 的最大值,其中 \(LCP\) 表示两个后缀的最长公共前缀. \(n\le 10^5\) 分析 ...
- 生成本地测试用https证书,支持通配符和多域名,初学OpenSSL
18-01-26在v2ex上看到一妹纸发的<身为一个 21 岁的年轻程序员,我已经腰突了(躺>,哈哈,感同身受,想到这几天我左腿麻木持续了好几天,前几天屁股疼的只要坐下就站不起来,不过站着 ...
- React学习-React初识
一.前言 为什么要去学习React呢,关于前端三大框架Angular,Vue,React其实都得去学吧,因为大家都在用啊,大家都再谈论啊,面试什么的都要求,没办法,曾几何时,大家都说求求大佬们别坑新了 ...
- Centos 7 部署Kubernetes(K8S)集群
资源链接:https://pan.baidu.com/s/1-PT_QQAf7cTu_znX-S-r9Q 密码:33sr 转发:http://blog.51cto.com/lizhenliang/19 ...
- Mysql的基本操作(一)增、删、改
创建/增加(create创建,alter字段操作,insert插入) 创建数据库 create database 数据库名称 charset=utf8; # 例: create database te ...
- 贪心Crossing river
英文题目: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...
- RYU 灭龙战 first day
RYU 灭龙战 first day 前言 由于RYU翻译过来是龙的意思,此次主题就叫灭龙战吧 灵感来源 恶龙的三位真火-问题所在 参照了官方文档的基本操作 笔者以此执行 一个终端里 sudo mn - ...
- “人向猿进阶”之软件工程第三课----WORDCOUNT.EXE统计程序
---恢复内容开始--- WC项目要求 这个项目要求写一个命令行程序,模仿已有的wc.exe的功能,并加以扩充,给出某程序设计源语言文件的字符数.单词数和行数.给实现一个统计程序,它能正确统计程序文件 ...
- Java的4种保留4位小数的方法(转)
上网查到的4种方法 其实刚学java……谁知道java里面的这么多方法啊……java里面重要的包本来就不少啊 ……跟我学粤语的小徒弟问我的东东…… 写两种方式……直接在main函数里面写的.还有就是利 ...
- Android控件第2类——ImageView
1.ImageView不仅仅可以显示图片,ImageView可以显示任何Drawable对象. adjustViewBounds:设置ImageView是否调整自己的边界来保证图片的长宽比. crop ...