spring+springmvc+mybatis(SSM)java从入门到放弃

springMVC整合FastDFS

2020-07-23  本文已影响0人  月影树下

1.pom添加依赖

<!--tobato-fastdfs上传下载工具-->
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.25.4-RELEASE</version>
</dependency>

2.配置环境

<!--配置扫描包-->
<context:component-scan base-package="com.github.tobato.fastdfs.service,com.github.tobato.fastdfs.domain"/>
<!--配置连接管理器-->
<bean id="trackerConnectionManager" class="com.github.tobato.fastdfs.conn.TrackerConnectionManager">
   <constructor-arg name="pool" ref="fdfsConnectionPool">
   </constructor-arg>
   <!--配置fastDFS tracker 服务器 ip:port 地址-->
        <property name="trackerList">
            <list>
                <value>42.159.8.47:22122</value>
            </list>
        </property>
</bean>
<!--配置连接池-->
<bean id="fdfsConnectionPool" class="com.github.tobato.fastdfs.conn.FdfsConnectionPool">
   <!--注入连接池配置-->
   <constructor-arg name="config" >
      <bean class="com.github.tobato.fastdfs.conn.ConnectionPoolConfig"/>
   </constructor-arg>
   <!--注入连接池工厂-->
   <constructor-arg name="factory" >
      <bean class="com.github.tobato.fastdfs.conn.PooledConnectionFactory"/>
   </constructor-arg>
</bean>

3.上传文件

// 注入工具类
@Autowired
private FastFileStorageClient fastFileStorageClient;

上传

// 调用上传方法,如果需要记录文件路径,group + path
File file = new File("D:\\壁纸\\UpupooResource\\2000134803\\image\\bg.png");
        StorePath storePath = fastFileStorageClient.uploadFile(null,new FileInputStream(file),file.length(),"png");

4.下载文件

<img src="http://42.159.8.47/group1/M00/00/00/CgAAD1ywSfmAeWiyABmzI8NVOSg500.png">

小结

下载,删除,参考上传功能即可

参考博客:https://blog.csdn.net/chen18677338530/article/details/93464624

上一篇下一篇

猜你喜欢

热点阅读