springMVC整合FastDFS

作者: 月影树下 | 来源:发表于2020-07-23 20:11 被阅读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

    相关文章

      网友评论

        本文标题:springMVC整合FastDFS

        本文链接:https://www.haomeiwen.com/subject/dnkclktx.html