Spring Boot 整合FastDFS

泪湿孤枕 提交于 2020-10-28 14:13:18

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

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!