FastDfs文件系统,目前只会使用,还不懂其中的原理呵,集成的的MyBatis的,以下是配置文件
fastdfs-client.properties:
fastdfs.connect_timeout_in_seconds = ${fastdfs.connect_timeout_in_seconds}
fastdfs.network_timeout_in_seconds = ${fastdfs.network_timeout_in_seconds}
fastdfs.charset = ${fastdfs.charset}
fastdfs.http_anti_steal_token = ${fastdfs.http_anti_steal_token}
fastdfs.http_secret_key = ${fastdfs.http_secret_key}
fastdfs.http_tracker_http_port = ${fastdfs.http_tracker_http_port}
fastdfs.tracker_servers = ${fastdfs.tracker_servers}
fastdfs.connect_timeout_in_seconds = 10
fastdfs.network_timeout_in_seconds = 30
fastdfs.charset = UTF-8
fastdfs.http_anti_steal_token = false
fastdfs.http_secret_key = FastDFS1234
fastdfs.http_tracker_http_port = 80
fastdfs.tracker_servers = //跟踪服务器
fastdfs.server.url=http: //服务器存储地址
工具包:调用其下一个
文件上传方法:
uploadFile(File file,String fileName);
uploadFile(文件文件,String fileName,Map <String,String> metaList);
uploadFile(byte [] file_buff,String fileName,Map <String,String> metaList);
>>获取元数据方法:
getFileMetadata(String fileId);
>>删除文件方法:
deleteFile(String fileId);
>>下载文件方法:
downloadFile(String fileId,File outFile)
downloadFile(String fileId)
公司系统集成用用用SpringMVC,文件上传
public Object upload(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception {
Map<String, Object> data = new HashMap<String, Object>();
try {
if (!file.isEmpty()) {
//获取文件名
String fileName = file.getOriginalFilename();
// 获取文件后缀
String prefix=fileName.substring(fileName.lastIndexOf("."));
// 用uuid作为文件名,防止生成的临时文件重复
final File excelFile = File.createTempFile(IdCreater.newId(), prefix);
file.transferTo(excelFile);
String path = FastDFSClient.uploadFile(excelFile, fileName);
String ur = url()+path; //这里的url方法是读取配置文件里的服务器地址,然后拼接一个完全的地址
data.put("dir", ur);
return renderSuccess(data);
} else {
return renderError();
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
return renderError();
}
需要对文件类型进行转换才能使用