fastDFS客户端工具类:
@Component
public class FastDFSUtil {
private static final Logger log = LoggerFactory.getLogger(FastDFSUtil.class);
private FastFileStorageClient storageClient ;
@Autowired
public FastDFSUtil(FastFileStorageClient storageClient){
this.storageClient = storageClient;
}
/**
* 上传文件
* @date 2020/5/29
* @param file 文件对象
* @return 文件路径
*/
public String uploadFile(MultipartFile file) throws IOException {
StorePath storePath = storageClient.uploadFile(file.getInputStream(),file.getSize(),
FilenameUtils.getExtension(file.getOriginalFilename()),null);
return storePath.getFullPath();
}
/**
* 上传文件
* @date 2020/5/29
* @param file 文件对象
* @return 文件访问地址
*/
public String uploadFile(File file) throws IOException {
FileInputStream inputStream = new FileInputStream (file);
StorePath storePath = storageClient.uploadFile(inputStream,file.length(), FilenameUtils.getExtension(file.getName()),null);
return storePath.getFullPath();
}
/**
* 上传图片
* @date 2020/5/29
* @param file 文件对象
* @return 文件路径
*/
public String uploadImage(MultipartFile file) throws IOException {
StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage(
file.getInputStream(),
file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()) , null);
return storePath.getFullPath();
}
/**
* 删除文件
* @date 2020/5/29
* @param fileUrl 文件路径
*/
public void deleteFile(String fileUrl) {
if (StringUtils.isEmpty(fileUrl))