首页 > 编程语言 > 详细

Spring Boot 整合FastDFS

时间:2019-08-14 19:47:47      阅读:161      评论:0      收藏:0      [点我收藏+]

1、在web层,导入依赖:

        <!--整合FastDFS-->
        <dependency>
            <groupId>com.github.tobato</groupId>
            <artifactId>fastdfs-client</artifactId>
            <version>1.26.1-RELEASE</version>
        </dependency>

2、启动类中添加注解:@Import(FdfsClientConfig.class)

@Import(FdfsClientConfig.class)
@SpringBootApplication
public class TestApplication { ... }

3、配置application.yml:

fdfs:
  so-timeout: 1500
  connect-timeout: 600
  pool:
    jmx-enabled: false
  thumb-image:
    width: 100
    height: 100
  tracker-list: 192.168.80.134:22122

4、测试:

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class MystoreProductWebApplicationTests {
    
            @Autowired
            private FastFileStorageClient fastFileStorageClient;
    
            @Test
            public void contextLoads() {
                    File file = new File("E:\\JavaProject\\mystore\\mystore-web\\mystore-product-web\\src\\main\\resources\\static\\timg.jpg");
                    try {
                            FileInputStream fis = new FileInputStream(file);
                            StorePath storePath = fastFileStorageClient.uploadImageAndCrtThumbImage(fis, file.length(), "JPG", null);
                            String fullPath = storePath.getFullPath();
                            String path = storePath.getPath();
                            //StorePath [group=group1, path=M00/00/00/wKhQhl0-aLOATq-QAAEWJNpzJ7c011.JPG]
                            System.out.println(storePath);
                            //group1/M00/00/00/wKhQhl0-aLOATq-QAAEWJNpzJ7c011.JPG
                            System.out.println(fullPath);
                            //M00/00/00/wKhQhl0-aLOATq-QAAEWJNpzJ7c011.JPG
                            System.out.println(path);
                    } catch (FileNotFoundException e) {
                            e.printStackTrace();
                    }
            }
}

 

 

 

Spring Boot 整合FastDFS

原文:https://www.cnblogs.com/Tractors/p/11354202.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!