FastDFS使用教程
FastDFS
- FastDFS服务端
- FastDFS客户端
- 1.导入maven
- 2.配置yml源代码
- 3.导入重复注入配置类
- 4.工具类配置
- 5.使用样例
FastDFS服务端
搭建FastDFS文件服务器
如果搭建服务器推荐地址csdn
https://blog.csdn.net/prcyang/article/details/89946190
FastDFS客户端
1.导入maven
<dependency><groupId>com.github.tobato</groupId><artifactId>fastdfs-client</artifactId><version>1.26.1-RELEASE</version>
</dependency>
2.配置yml源代码
fdfs:so-timeout: 1500001connect-timeout: 600001thumb-image: # 缩略图width: 60height: 60tracker-list: # tracker地址- xxx.xxx.xxx.xxx:22122view-ip: http://xxx.xxx.xxx.xxx/
3.导入重复注入配置类
package com.xxx.xxx.xxx;import com.github.tobato.fastdfs.FdfsClientConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;@Configuration
@Import(FdfsClientConfig.class)
// 解决jmx重复注册bean的问题
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class FastClientImporter {}
4.工具类配置
package com.xxx.upload.util;import com.github.tobato.fastdfs.service.DefaultFastFileStorageClient;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;@Service
public class FastDFSUtil implements ApplicationContextAware {@Autowiredprivate ApplicationContext applicationContext;//获取一个命令public FastFileStorageClient getClient() {return (DefaultFastFileStorageClient) this.applicationContext.getBean(DefaultFastFileStorageClient.class); //}@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {this.applicationContext = applicationContext;//获得该ApplicationContext引用}
}
5.使用样例
public String uploadFile(MultipartFile file){try {result = "";InputStream inputStream = file.getInputStream();String md5Hex = DigestUtils.md5Hex(inputStream);String pathByMD5 = fileMd5RecordService.getPathByMD5(md5Hex);if (pathByMD5 != null){result = pathByMD5;}else{//上传文件FastFileStorageClient fastFileStorageClient = fastDFSUtil.getClient();String extension = StringUtils.substringAfterLast(file.getOriginalFilename(), ".");StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), extension, null);// 返回路径result = storePath.getFullPath();}} catch (Exception e) {e.printStackTrace();}
}
本文章只是一个简单的Demo项目搭建,如果更多使用FastDFS,作者找到一个地址:
https://blog.csdn.net/qq_37128049/article/details/98885201
有更好的有参考价值;
FastDFS使用教程相关推荐
- Linux 安装FastDFS 图解教程
1.创建fastdfs安装目录,我的是在etc/fastdfs. 由于我在虚拟机搭建 首先在etc目录下的hosts文件添加一行IP地址 192.168.1.14 file.gaci.com 如果要本 ...
- 分布式文件管理系统FastDFS搭建教程(FastDFS+nginx+fastdfs-nginx-module)
Why FastDFS? FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以 ...
- 分布式文件系统FastDFS安装教程
前言 FastDFS(Fast Distributed File System)是一款开源轻量级分布式文件系统,本文不讲解原理和架构,只是在个人使用部署过程中耗费了好长时间和精力,遇到了很多的坑,于是 ...
- FastDFS安装教程
第一步:安装相关依赖 1.没有编译环境的需要安装一下 yum -y install gcc-c++ 2.安装一下fastDFS相关依赖库 yum -y install libevent 第二部: ...
- 分布式文件存储FastDFS使用教程(下载安装使用)
分布式文件存储FastDFS 1.FastDFS 1.1 FastDFS简介 1.1.1 FastDFS体系结构 1.1.2 上传流程 1.2 FastDFS搭建 1.2.1 安装FastDFS镜像 ...
- 【转雷哥】FastDFS安装教程直接复制实测【最新安装包】
精选30+云产品,助力企业轻松上云!>>> 一.安装fastDFS需要分别安装fastdfs-nginx-module,fastdfs,nginx,libfastcommon 百度云 ...
- linux下载安装fastdfs和fastdfs与nginx整合、springboot访问fastdfs
文章目录 需求分析 分布式文件系统 1 FastDFS安装 FastDFS 和nginx整合 2.整合java访问fastdfs服务 文件上传查询下载测试 整合springboot 需求分析 搭建fa ...
- 分布式文件系统研究-fastDFS安装及配置文件说明
fastDFS安装 如果想自己尝试安装fastDSF也可以按照文档一步一步安装. tracker和storage使用相同的安装包,fastDFS的下载地址在:https://github.com/ha ...
- fastdfs暗转 linux_Linux下安装fastDFS
1.Linux下使用FastDFS 本教程所有操作均在CentOS 6.x环境下进行. 文件下载: 链接:https://pan.baidu.com/s/1vVEfCeOHnaftvV0DPtbgWg ...
最新文章
- android获取指针空间大小_腾讯笔试题:浅谈计算机中cpu位数和指针
- MDX学习笔记(整理) MDX语法
- tomcat8.5 远程访问 manager页面
- struts2处理.do后缀的请求
- 常用的机器学习数据挖掘知识点【转】
- Adobe Dreamweaver 添加库、标签和属性
- tmux常用命令(分屏工具)
- VSCode打开底部状态栏
- appium使用真机做安卓移动端自动化测试
- 【扫描线】【POJ-1177】Picture【周长并】
- python实现常见的设计模式
- 魔兽世界服务器开启mysql_魔兽世界服务端Trinity编译安装
- Coursera课程自然语言处理(NLP) 借助概率模型做自然语言处理 deeplearning.ai
- Mac下Android studio怎么格式化代码
- win10自动修复无法修复你的电脑的解决方法(操作+原理理解)
- 4.STM32下载不进程序、程序不运行的可能原因
- 如何申请edi许可证
- java创建exe程序快捷方式
- 2021.8.27夏令营阶段测试总结
- Cloudberry Drive的神用法