fastdfs java client_fastdfs-client使用教程

本文档介绍了如何在SpringBoot和SpringMVC项目中使用fastdfs-client,包括添加依赖、配置属性以及在业务代码中调用上传下载方法。提供详细步骤和配置示例。
摘要由CSDN通过智能技术生成

FastDfs客户端使用文档

fastdfs-client支持框架

fastdfs-client目前支持的框架有springboot1.x 、springboot2.x、springmvc

添加fastdfs-client依赖

springboot项目

项目pom.xml文件中增加jar包依赖

com.msun

fastdfs-client-springboot

1.0-SNAPSHOT

项目启动类增加注解支持

@SpringBootApplication

@EnableFastDfsClient

public class BailingServiceFaceverifyApplication {

public static void main(String[] args) {

SpringApplication.run(BailingServiceFaceverifyApplication.class, args);

}

}

application.properties文件中增加fastdfs相关配置文件

## fastdfs-client.properties

fastdfs.connect_timeout_in_seconds = 5

fastdfs.network_timeout_in_seconds = 30

fastdfs.charset = UTF-8

fastdfs.http_anti_steal_token = false

fastdfs.http_secret_key = FastDFS1234567890

fastdfs.http_tracker_http_port = 80

fastdfs.tracker_servers = 185.245.40.70:22122

## Whether to open the connection pool, if not, create a new connection every time

fastdfs.connection_pool.enabled = true

## max_count_per_entry: max connection count per host:port , 0 is not limit

fastdfs.connection_pool.max_count_per_entry = 500

## connections whose the idle time exceeds this time will be closed, unit: second, default value is 3600

fastdfs.connection_pool.max_idle_time = 3600

## Maximum waiting time when the maximum number of connections is reached, unit: millisecond, default value is 1000

fastdfs.connection_pool.max_wait_time_in_ms = 1000

在业务代码中直接注入FastDfsClient类即可调用相关上传下载等方法

@Autowired

private FastDfsClient fastDfsClient;

springmvc项目

项目pom.xml文件中增加jar包依赖

com.msun

fastdfs-client-springmvc

1.0-SNAPSHOT

在类路径下创建fdfs_client.conf文件,内容为

## fastdfs-client.properties

fastdfs.connect_timeout_in_seconds = 5

fastdfs.network_timeout_in_seconds = 30

fastdfs.charset = UTF-8

fastdfs.http_anti_steal_token = false

fastdfs.http_secret_key = FastDFS1234567890

fastdfs.http_tracker_http_port = 80

fastdfs.tracker_servers = 185.245.40.70:22122

## Whether to open the connection pool, if not, create a new connection every time

fastdfs.connection_pool.enabled = true

## max_count_per_entry: max connection count per host:port , 0 is not limit

fastdfs.connection_pool.max_count_per_entry = 500

## connections whose the idle time exceeds this time will be closed, unit: second, default value is 3600

fastdfs.connection_pool.max_idle_time = 3600

## Maximum waiting time when the maximum number of connections is reached, unit: millisecond, default value is 1000

fastdfs.connection_pool.max_wait_time_in_ms = 1000

在业务代码中直接通过FastDfsClient类即可调用相关上传下载等方法

本文地址:https://blog.csdn.net/springdata_/article/details/107247163

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。 存储节点存储文件,完成文件管理的所有功能:就是这样的存储、同步和提供存取接口,FastDFS同时对文件的metadata进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key value)方式表示,如:width=1024,其中的key为width,value为1024。文件metadata是文件属性列表,可以包含多个键值对。 跟踪器和存储节点都可以由一台或多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的,可以根据服务器的压力情况随时增加或减少。 为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。 在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。 当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。 FastDFS中的文件标识分为两个部分:卷名和文件名,二者缺一不可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值