FastDFS基础(上传、下载)

目录

FastDFS介绍

文件上传的流程

文件下载的流程

FastDFS在linux的安装

java操作FastDFS上传文件

fastDFS的配置文件

实际开发下的文件上传


前言

FastDFS是一个分布式文件服务器,专门用来存放文件的

FastDFS介绍

tracker(追踪)就是管理集群的,这样当我们添加服务器,就能进行,对接,管理

每个组的数据,数据是完全一样的

文件上传的流程

文件下载的流程

第3步其实是查询自身,查询可用的storage

FastDFS在linux的安装

因为访问FastDFS需要Nginx容器,所以这里先配置Nginx

https://blog.csdn.net/yzj17025693/article/details/90550812

java操作FastDFS上传文件

需要从网上下载对应的jar包,然后安装到maven仓库

添加依赖

fastDFS的配置文件

# 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.23.132: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

第3个参数是文件的扩展信息,比如尺寸之类的

实际开发下的文件上传

把之前繁琐的操作修改成工具类

因为上传图片的原因,所以还需要

下面一个是存储文件的路径,一个是存储实际的字节

在配合spring mvc的情况下

还需要配置多媒体解析器

1 获取配置文件里的值,这个就是一个简单的ip地址,用于拼接完整请求路径的

2 获取文件的扩展名

3 然后加载fdfs_client.conf,这个conf就是fastDFD的地址+端口,上传之后,会返回一个url,也就是文件名存储路径

这是file_server_url的获取来源

前台的写法

https://blog.csdn.net/yzj17025693/article/details/88586779#上传文件的前台写法

发布了143 篇原创文章 · 获赞 36 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/yzj17025693/article/details/90300993
今日推荐