FastDFSの基本的な使い方
1295 ワード
インストールドキュメントはcentOSインストールFastDFSを参照
Javaの使用方法:依存 を導入
2.構成クラスの導入
3.構成クラスの作成
4.クラス内
return : group1/M00/00/00/wKgemFwODaGAZ0OZAADJSKSfgD0811.jpg
アクセス先:address/group 1/M 00/00/wKgemFwODaGAZ 0 OZAADJSKSfgD 0811.jpg
Javaの使用方法:
com.github.tobato
fastdfs-client
2.構成クラスの導入
@Configuration
@Import(FdfsClientConfig.class)
// jmx bean
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class FastClientImporter {
}
3.構成クラスの作成
fdfs:
so-timeout: 1501
connect-timeout: 601
thumb-image: #
width: 60
height: 60
tracker-list: # tracker
- address:port
4.クラス内
@Autowired
private FastFileStorageClient storageClient;
@PostMapping("/image")
public ResponseEntity uploadImage(@RequestParam("file") MultipartFile file) {
StorePath storePath = null;
try {
storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), "jpg", null);
} catch (IOException e) {
e.printStackTrace();
}
// 200, url
return ResponseEntity.ok(storePath.getFullPath());
}
return : group1/M00/00/00/wKgemFwODaGAZ0OZAADJSKSfgD0811.jpg
アクセス先:address/group 1/M 00/00/wKgemFwODaGAZ 0 OZAADJSKSfgD 0811.jpg