FastDFS文件传输系统

FastDFS是用c语言编写的一款开源的分布式文件系统,它是由淘宝资深架构师余庆编写并开源。FastDFS专为互联网量身定制,充分考虑了冗余备份负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很 容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务

第一步导入依赖

            <!--FastDFS客户端-->
            <dependency>
                <groupId>com.github.tobato</groupId>
                <artifactId>fastdfs-client</artifactId>
                <version>${fastDFS.client.version}</version>
            </dependency>

            <fastDFS.client.version>1.26.1-RELEASE</fastDFS.client.version>

第二步:编写配置类


@Configuration
@Import(FdfsClientConfig.class)
/*解决jmx重复注册bean的问题*/
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class FastclientImporter {
}

第三步:配置yml文件

fdfs:
  so-timeout: 1501 # 读取时间 
  connect-timeout: 601 #连接超时时间
  thumb-image:   #缩略图
    height: 60
    width: 60
  tracker-list: #tracker地址:你的虚拟机服务器地址+端口(默认是22122)
    xxxxxx:22122 例如: 192.168.56.101:22122

第四步:进行测试

@SpringBootTest
@RunWith(SpringRunner.class)
public class FastDFSTest {
    @Autowired
    private FastFileStorageClient fastFileStorageClient;
    @Autowired
    private ThumbImageConfig thumbImageConfig;
    /*上传文件*/
    @Test
    public void testUplod() throws FileNotFoundException {
        /*上传文件的文件*/
        File  file = new File("xxx路径//1.jpg");
        /*上传并保存的图片:参数 1、上传的文件流 2、文件的大小 3、文件的后缀 4、设置*/
        StorePath jpg = this.fastFileStorageClient.uploadFile(new FileInputStream(file), file.length(), "jpg", null);
        //带分组的路径
        System.out.println(jpg.getFullPath());
        //不带分组的路径
        System.out.println(jpg.getPath());
    }
    /*上传文件带缩略图*/
    @Test
    public void testUploadAndSUOLUETU() throws FileNotFoundException {
        File  file = new File("xxx路径//1.jpg");
        StorePath jpg = this.fastFileStorageClient.uploadImageAndCrtThumbImage(new FileInputStream(file), file.length(), "png", null);
        //带分组的路径
        System.out.println(jpg.getFullPath());
        //不带分组的路径
        System.out.println(jpg.getPath());
        //获取缩略图的路径
        String thumbImagePath = thumbImageConfig.getThumbImagePath(jpg.getPath());
        System.out.println(thumbImagePath);
    }
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值