ueditor默认的文件上传是依靠commons-fileupload插件,提供上传服务的就是启动了我们项目的tomcat容器。我们了解了ueditor与fastdfs,我们也了解了fastdfs-client,这篇文章我们将阐述整合ueditor与fastdfs。
以下图所示方式创建【去掉ueditor jar包,加入fastdfs_client-1.25.jar,导入去掉的jar包的源码,功能不受任何影响,但却为我们文件修改上传方式提供了前提】:
String getInfo(String name);
因为该接口多增加一个方法,那么接口的实现类也要增加该方法实现:
在com.baidu.ueditor.define.MultiState.java以及com.baidu.ueditor.define.BaseState.java中增加方法实现:
@Override
public String getInfo(String name) {
return this.infoMap.get(name);
}
"imageUrlPrefix": "http://192.168.100.192/", /* 图片访问路径前缀 */
tracker_server=192.168.100.192:22122
static{
try {
ClientGlobal.init(new URLDecoder().decode(StorageManager.class.getClassLoader().getResource("/").getPath())+"/"+"trackerClient.conf");
}
catch(Exception e)
{
}
}
private static State saveTmpFile(File tmpFile, String path) {
State state = null;
File targetFile = new File(path);
if (targetFile.canWrite()) {
return new BaseState(false, AppInfo.PERMISSION_DENIED);
}
/*try {
FileUtils.moveFile(tmpFile, targetFile);
} catch (IOException e) {
return new BaseState(false, AppInfo.IO_ERROR);
}*/
//保存图片到服务器上========================================
try {
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String[] strings = storageClient.upload_file(tmpFile.getPath(), FileType.getSuffixByFilename(targetFile.getName()).substring(1), null);
String url = strings != null ? strings[0] + "/" + strings[1] : null;
state = new BaseState(true);
state.putInfo("url",url);
}
catch(Exception e)
{
e.printStackTrace();
}
//保存图片到服务器上========================================
return state;
}
if (storageState.isSuccess()) {
storageState.putInfo("url", PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}
改为
if (storageState.isSuccess()) {
storageState.putInfo("url", storageState.getInfo("url"));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}
在http的server节点中增加一个location映射
location /group1/M00 {
#映射逻辑路径到物理路径,倘若url中出现"/group1/M00",则替换为"/root/docker/fastdfs/storage/data"
alias /root/docker/fastdfs/storage/data;
}
原文:https://www.cnblogs.com/alichengxuyuan/p/12581338.html