Spring Boot 整合FastDFS

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();
                    }
            }
}

 

 

 

posted @ 2019-08-14 19:32  开拖拉机的拉风少年  阅读(666)  评论(0编辑  收藏  举报