1.环境安装:
参考:
https://blog.youkuaiyun.com/cencfeng11/article/details/95977300
fastDFS已经配置完成
https://github.com/happyfish100/fastdfs-client-java下载源码
命令:
mvn clean install
ant clean package (先安装ant)
mvn install:install-file -DgroupId=org.csource -DartifactId=fastdfs-client-java -Dversion=5.0.4 -Dpackaging=jar -Dfile=D:\fastdfs-java\fastdfs-client-java-1.27-SNAPSHOT.jar -----(名称)
原命令为:
mvn install:install-file -DgroupId=org.csource -DartifactId=fastdfs-client-java -Dversion=${version} -Dpackaging=jar -Dfile=fastdfs-client-java-${version}.jar
java代码:
- 新建文件fdfs_client.conf,内容为,本次通过配置文件配置,静态模块初始化
connect_timeout = 60
network_timeout = 60
charset = UTF-8
http.tracker_http_port = 8999
http.anti_steal_token = no
http.secret_key = 123456
tracker_server = 18.223.50.104:22122
- 新建FastDFSClient类
package com.fashion.mjysite.util;
import com.fashion.mjysite.entity.FastDFSFile;
import org.csource.fastdfs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.csource.common.NameValuePair;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
public class FastDFSClient {
private static final Logger logger = LoggerFactory.getLogger(FastDFSClient.class);
//使用static模块初始化配置
static {
try {
String filePath = new ClassPathResource("fdfs_client.conf").getFile().getAbsolutePath();;
ClientGlobal.init(filePath);
} catch (Exception