資源簡介
FastDFS 整合java實例

代碼片段和文件信息
package?com.caoyong.common.fastdfs;
import?org.apache.commons.io.FilenameUtils;
import?org.apache.commons.lang3.builder.ToStringBuilder;
import?org.apache.commons.lang3.builder.ToStringstyle;
import?org.csource.common.NameValuePair;
import?org.csource.fastdfs.ClientGlobal;
import?org.csource.fastdfs.StorageClient1;
import?org.csource.fastdfs.TrackerClient;
import?org.csource.fastdfs.TrackerServer;
import?org.springframework.core.io.ClassPathResource;
import?lombok.extern.slf4j.Slf4j;
/**
?*?FastDFS工具類
?*?@author?yong.cao
?*?@time?2017年6月14日下午10:31:05
?*/
@Slf4j
public?class?FastDFSUtils?{
public?static?String?uploadPic(UploadFileVo?vo){
log.info(“uploadPic?start.?vo:{}“?ToStringBuilder.
reflectionToString(vo?ToStringstyle.DEFAULT_style));
String?path?=?null;
//clientGloble讀配置文件
ClassPathResource?resource?=?new?ClassPathResource(“fdfs_client.conf“);
try?{
ClientGlobal.init(resource.getClassLoader().getResource(“fdfs_client.conf“).getPath());
//trackerclient
TrackerClient?trackerclient?=?new?TrackerClient();
TrackerServer?trackerServer?=?trackerclient.getConnection();
//storageclient
StorageClient1?storageClient1?=?new?StorageClient1(trackerServernull);
//文件擴展名
String?ext?=?FilenameUtils.getExtension(vo.getName());
//mata?list是表文件的描述
NameValuePair[]?mata_list?=?new?NameValuePair[3];
mata_list[0]?=?new?NameValuePair(“fileName“vo.getName());
mata_list[1]?=?new?NameValuePair(“fileExt“ext);
mata_list[2]?=?new?NameValuePair(“fileSize“String.valueOf(vo.getSize()));
path?=?storageClient1.upload_file1(vo.getPic()?ext?mata_list);
}?catch?(Exception?e)?{
log.error(“uploadPic?error:{}“e.getMessage()e);
}?
return?path;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-06-17?22:41??fastdfs-client-demo\
?????文件????????1825??2017-06-15?23:00??fastdfs-client-demo\FastDFSUtils.java
?????文件????????2179??2017-06-16?23:25??fastdfs-client-demo\UploadController.java
?????文件?????????476??2017-06-14?23:57??fastdfs-client-demo\UploadFileVo.java
?????文件?????????386??2017-06-14?23:28??fastdfs-client-demo\UploadService.java
- 上一篇:J2EE期末復習題匯總
- 下一篇:銀行家算法java實現
評論
共有 條評論