1.pom依赖
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.7</version>
</dependency>
2.application.yml配置
fdfs:
connect-timeout: 30 # 连接的超时时间
so-timeout: 30 # 读取的超时时间
tracker-list: 192.168.174.128:22122 #tracker服务所在的ip地址和端口号
3.Service
package com.imooc.service.impl;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.imooc.service.FdfsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
public class FdfsServiceImpl implements FdfsService {
@Autowired
FastFileStorageClient fastFileStorageClient;
@Override
public String upload(MultipartFile file, String fileExtName) throws Exception {
StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(),fileExtName, null);
String path = storePath.getFullPath();
return path;
}
}