tfs配置

tfs上传文件.有什么不懂的 淘宝官方文档


maven里面加入夹包

com.taobao.common.tfs

com.taobao.tair

<dependency>
    <groupId>com.taobao.common.tfs</groupId>
    <artifactId>common-tfs</artifactId>
    <version>2.1.6</version>
</dependency>

tfs.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
	default-autowire="byName">

	<bean id="tfsClient" class="com.taobao.common.tfs.DefaultTfsManager"
		init-method="init">
		<!-- 整个进程中系统最多等待多少个请求,取决于你有多少个线程并发的请求TFS -->
		<property name="maxWaitThread" value="100" />
		<!-- 单个请求最大的等待时间(ms) 超过这个时间放弃这次请求 -->
		<property name="timeout" value="20000" />
		<!-- Tfs master nameserver ip address -->
		<property name="nsip" value="192.168.1.154:8108" />
		<!-- TFS 集群的编号,这个编号只是一种参考,系统初始化的时候会从ns上取,取不到才用本地设置的.! -->
		<property name="tfsClusterIndex" value="1" />
		 <!-- TFS在读取文件的时候会缓存block所在的数据服务器ip,这个参数配置了最多缓存的记录个数! -->
		<property name="maxCacheItemCount" value="10000" />
 		<!-- 上一项缓存最大有效的时间(ms)! -->
		<property name="maxCacheTime" value="5000" />
  	</bean>
</beans>



java用法:

File file;//文件
String pex = "png";//文件扩展名
String fileName = tfsClient.saveFile(file, null, pex);//上传到tfs上面,返回一个字符串(图片名称)
String tfsUrl = "http://192.168.1.156:8089/file/";//tfs读取文件地址
tfsUrl + fileName//这就是文件在tfs的访问地址


官方文档java使用






posted @ 2022-10-27 08:48  何童鞋  阅读(39)  评论(0编辑  收藏  举报