Springboot整合fastdfs

最近的学习总结巩固

fastdfs环境搭建

1、在linux服务器上创建目录:/usr/local/docker/fastdfs/environment
2、在/usr/local/docker/fastdfs 路径下创建docker-compose.yml文件
3、在/usr/local/docker/fastdfs/environment目录下创建Dockerfile
4、复制fastdfs的相关依赖包到/usr/local/docker/fastdfs/environment下
执行 unzip [
.zip]进行解压缩
5、给entrypoint.sh赋予执行权限
chmod +x entrypoint.sh
6、修改各种配置文件参考内容fastdfs的文档中各种配置文件说明部分*

springboot整合fastdfs

1、导入pom相关依赖

<!-- 添加fastdfs的依赖-->
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.26.1-RELEASE</version>
</dependency>

2、在入口类导入fastdfs的配置类

@Import(FdfsClientConfig.class)
@SpringBootApplication
public class SpringBootFastdfsDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootFastdfsDemoApplication.class, args);
    }
}

3、在application.yml中配置fastdfs的连接信息

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

4、写具体连接业务

package com.qf.springbootfastdfsdemo.controller;

import com.github.tobato.fastdfs.FdfsClientConfig;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;


@Controller
public class MyController {

    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    @RequestMapping("upload")
    @ResponseBody
    public String upLoadFile(){
        String fullPath=null;

        File file =new File("C:\\Users\\Desktop\\bmw.jpg");
        try {
            StorePath storePath = fastFileStorageClient.uploadFile(new FileInputStream(file),
                    file.length(), "JPG", null);
         fullPath = storePath.getFullPath();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return fullPath;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值