介绍
这篇文章主要为大家展示了SpringBoot怎么整合FastDFS,内容简而易懂,希望大家可以学习一下,学习完之后肯定会有收获的,下面让小编带大家一起来看看吧。
<强>一.pom。xml 强>
& lt;及# 63;xml version=?.0”;编码=癠TF-8", # 63;比; http://maven.apache.org/POM/4.0.0" & lt;项目xmlns=?xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" ,xsi: schemaLocation=癶ttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"的在; & lt; modelVersion> 4.0.0 & lt; parent> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-parent & lt; version> 2.2.6.RELEASE & lt; relativePath/比;& lt; !——从库中查找父——比; & lt;/parent> & lt; groupId> com.wj & lt; artifactId> fastdsf-boot & lt; version> 0.0.1-SNAPSHOT & lt; name> fastdsf-boot 春天Boot< & lt; description>演示项目;/description> & lt; properties> & lt; java.version> 1.8 & lt;/java.version> & lt;/properties> & lt; dependencies> & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter & lt;/dependency> & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-web & lt;/dependency> & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-thymeleaf & lt;/dependency> & lt; dependency> & lt; groupId> com.github.tobato & lt; artifactId> fastdfs-client & lt; version> 1.26.2 & lt;/dependency> & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-test & lt; scope> test & lt; exclusions> & lt; exclusion> & lt; groupId> org.junit.vintage & lt; artifactId> junit-vintage-engine & lt;/exclusion> & lt;/exclusions> & lt;/dependency> & lt;/dependencies> & lt; build> & lt; plugins> & lt; plugin> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-maven-plugin & lt;/plugin> & lt;/plugins> & lt;/build> & lt;/project>
<强>二类。yml 强>
# fastdfs配置
引用>
fdfs:
so-timeout: 150000
connect-timeout: 150000 #超时时间
thumb-image:
宽度:150
身高:150
tracker-list:
- 111.111.111.111:22122 # ip:端口号
春:
thymeleaf:
前缀:类路径:/模板/servlet
:
多部分:
max-file-size: 50 mb #单次单个文件最大大小
max-request-size: 50 mb #单次上传所有文件的总大小& lt; br>#注意,这里springboot默认配置的大小是1 mb和10 mb,可能不够用,具体参考MultipartProperties。java
<强>三.FastUtil。java前提先将Nginx和FastDFS整合强>
@ component 公开课FastUtil { 私人最后日志记录器=LoggerFactory.getLogger (FastUtil.class); @ autowired 私人FastFileStorageClient FastFileStorageClient;/* * *文件上传 *最后返回fastDFS中的文件名称; * * @param字节文件字节 * @param文件大小文件大小 * @param扩展文件扩展名 * @return fastDfs路径 */还是公共字符串(byte[]字节,文件大小,字符串扩展){ ByteArrayInputStream ByteArrayInputStream=new ByteArrayInputStream(字节);=fastFileStorageClient路径路径。还是(byteArrayInputStream、文件大小、扩展,null); 返回“http://111.111.111.111/" + storePath.getFullPath (); } 公共byte [] downloadFile(字符串,字符串路径)抛出IOException { DownloadByteArray DownloadByteArray=new DownloadByteArray ();=fastFileStorageClient byte[]字节。downloadFile(集团、路径、downloadByteArray); 返回字节; } }<强>四。配置类FdfsConfig。java 强>
@ configuration @ import (FdfsClientConfig.class) @EnableMBeanExport(注册=RegistrationPolicy.IGNORE_EXISTING) 公开课FdfsConfig { }<强>五。控制器
SpringBoot怎么整合FastDFS