我在网上找了一圈没找到ueditor的upyun存储java处理,upyun官方提供了php的,
而公司使用的项目是java编写的。只能对ueditor的源码包稍作修改满足需求。
ueditor目录结构,只要修改文件的存储位置,所有只修改upload包下相关的文件即可。
1、修改存储路径
Base64Uploader.java和BinaryUploader.java下
// String physicalPath = (String) conf.get("rootPath") + savePath;
String physicalPath = savePath;
去掉拼接rootPath的路径。
2、修改存储管理类StorageManager.java
发现类中3个public的方法2个参数流,另一个参数字节数组。流存储都调用相同的方法saveTmpFile;
于是把原方法
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);
}
state = new BaseState(true);
state.putInfo( "size", targetFile.length() );
state.putInfo( "title", targetFile.getName() );
return state;
}
修改为
private static State saveTmpFile(File tmpFile, String path) {
State state = null;
try {
boolean upload = UpYunFileUtils.upload(path, tmpFile, null);
if (!upload) {
return new BaseState(false, AppInfo.IO_ERROR);
}
} catch (IOException e) {
return new BaseState(false, AppInfo.IO_ERROR);
}
path = path.substring(path.lastIndexOf("/")+1, path.length());
state = new BaseState(true);
state.putInfo( "size", tmpFile.length() );
state.putInfo( "title", path );
return state;
}
UpYunFilleUtils类是我在上面文章写upyun封装的。
现在还剩一个字节数组的方法需要处理,如下:
public static State saveBinaryFile(byte[] data, String path) {
State state = null;
try {
boolean upload = UpYunFileUtils.upload(path, data, null);
if (!upload) {
return new BaseState(false, AppInfo.IO_ERROR);
}
} catch (Exception ioe) {
return new BaseState(false, AppInfo.IO_ERROR);
}
state = new BaseState(true, path);
path = path.substring(path.lastIndexOf("/")+1, path.length());
state.putInfo( "size", data.length );
state.putInfo( "title", path);
return state;
}
现在管理jar包已经修改了,编译生成ueditor.upyun.jar,引入使用的项目。
最后把ueditor配置修改下。
修改ueditor/jsp/config.json配置
imageUrlPrefix:"又拍云图片域名"