1、在項目中添加依靠到Maven的pom文件
<!-- fastdfs-client -->
<dependency>
<groupId>org.csource</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
2、FastDFS客戶端東西類,已封裝如下(便利直接利用),
本家兒要東西類方式:
/**
* @Description 文件存儲上傳客戶端
* @author javaer
* @time 2020年5月30日 上午9:27:26
*/
public class FastDFSClient {
/**
* MultipartFile 上傳文件
*
* @param file MultipartFile
* @return 返回上傳當作功后的文件路徑
*/
public static String uploadFileWithMultipart(MultipartFile file) throws BusinessException {
return upload(file, null);
}
/**
* 以附件形式下載文件
*
* @param filepath 文件路徑
* @param response
*/
public static void downloadFile(String filepath, HttpServletResponse response) throws BusinessException {
download(filepath, null, null, response);
}
/**
* 刪除文件
* @param filepath 文件路徑
* @return 刪除當作功返回 0, 掉敗返回其它
*/
public static int deleteFile(String filepath) throws BusinessException {
if (StringUtils.isBlank(filepath)) {
throw new BusinessException(FileErrorCode.FILE_PATH_ISNULL.CODE);
}
TrackerServer trackerServer = TrackerServerPool.borrowObject();
StorageClient1 storageClient = new StorageClient1(trackerServer, null);
int success = 0;
try {
success = storageClient.delete_file1(filepath);
if (success != 0) {
throw new BusinessException(FileErrorCode.FILE_DELETE_FAILED.CODE);
}
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
throw new BusinessException(FileErrorCode.FILE_DELETE_FAILED.CODE);
}
// 返還對象
TrackerServerPool.returnObject(trackerServer);
return success;
}
}
 
 3、將fastdfs-client.properties設置裝備擺設文件放置于引用項目標resource目次下
 4、如下圖,在項目中可直接經由過程FastDFSClient東西類挪用所用的方式
 5、項目中上傳文件后利用的結果,由前端頁面上傳文件,至此項目實現分布式存儲。
 
 END0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!