最近的学习总结巩固
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;
}
}