UEditor扩展上传
来源:互联网 发布:天刀女性明星捏脸数据 编辑:程序博客网 时间:2024/04/30 20:35
1.修改配置文件ueditor.config.js,重写后台请求方法,serverUrl
if(!window.UEDITOR_HOME_URL){window.UEDITOR_HOME_URL = "/lw-component/component/module/ueditor/";} var URL = window.UEDITOR_HOME_URL || getUEBasePath(); /** * 配置项主体。注意,此处所有涉及到路径的配置别遗漏URL变量。 */ window.UEDITOR_CONFIG = { //为编辑器实例添加一个路径,这个不能被注释 UEDITOR_HOME_URL: URL // 服务器统一请求接口路径 , serverUrl: "/xxx-component/component/ueditor/exec"
@Controller@RequestMapping("/component/ueditor")public class UEditorController extends SpringController {@RequestMapping(value = "/exec", method = RequestMethod.GET)@ResponseBodypublic void exec(){String jsonFilePath=getRequest().getServletContext().getRealPath(UEditorConstant.CONFIG_FILEPATH);String actionType = getRequest().getParameter("action");if(actionType.equals(UEditorConstant.CONFIG)){this.print(UEditorUtil.getAllConfig(jsonFilePath));}else{Map<String, Object> config = UEditorUtil.getConfig(actionType, jsonFilePath);this.print(JsonUtil.map2Json(config));}}@RequestMapping(value = "/exec", method = RequestMethod.POST)@ResponseBodypublic void exec(@RequestParam(value = "upfile") MultipartFile file){String jsonFilePath=getRequest().getServletContext().getRealPath(UEditorConstant.CONFIG_FILEPATH);String actionType = getRequest().getParameter("action");if(actionType.equals(UEditorConstant.CONFIG)){this.print(UEditorUtil.getAllConfig(jsonFilePath));}else{Map<String, Object> returnMsg=new HashMap<String, Object>();//上传图片String filename = file.getOriginalFilename();returnMsg.put("original", filename);returnMsg.put("title", filename);String filePath=UEditorConstant.STORE_DIR_UEDITOR+AttachmentUtil.getRelativePath();File dir=new File(filePath);if (!dir.exists()) {dir.mkdirs();}String newFileName = UUID.getUUID() + "." + FilenameUtils.getExtension(filename);File newFile = new File(dir+ "/"+ newFileName);try {//保存图片file.transferTo(newFile);returnMsg.put("state", "SUCCESS");//TODOreturnMsg.put("url", "");} catch (IOException e) {e.printStackTrace();}this.print(JsonUtil.map2Json(returnMsg));}}
public class UEditorConstant {//初次加载配置public static final String CONFIG = "config";//上传图片public static final String UPLOAD_IMAGE = "uploadimage";//上传涂鸦public static final String UPLOAD_SCRAWL = "uploadscrawl";//上传视频public static final String UPLOAD_VIDEO = "uploadvideo";//上传文件public static final String UPLOAD_FILE = "uploadfile";//抓图截图public static final String CATCH_IMAGE = "uploadimage";//列出文件public static final String LIST_FILE = "listfile";//列出图片public static final String LIST_IMAGE = "listimage";//配置文件的路径public static final String CONFIG_FILEPATH = "/component/module/ueditor/jsp/config.json";//富文本图片的保存地址public static final String STORE_DIR_UEDITOR = "D:"+ "/" +"upload"+ "/" +"ueditor"+ "/";}
4.方法:从文件中获取配置信息,转成json对象
public class UEditorUtil {public static String getAllConfig(String jsonFilePath){return readJsonFile(jsonFilePath);}public static Map<String, Object> getConfig(String type,String jsonFilePath) {JSONObject jsonConfig=JSONObject.parseObject(readJsonFile(jsonFilePath));Map<String, Object> conf = new HashMap<String, Object>();if(type.equals(UEditorConstant.UPLOAD_IMAGE)){//上传图片conf.put("imageMaxSize", jsonConfig.getLong("imageMaxSize"));conf.put("imageAllowFiles", jsonConfig.getJSONArray("imageAllowFiles"));conf.put("imageFieldName", jsonConfig.getString("imageFieldName"));conf.put("imageCompressEnable", jsonConfig.getBoolean("imageCompressEnable"));conf.put("imageCompressBorder", jsonConfig.getInteger("imageCompressBorder"));}return conf;}private static String readJsonFile(String path){StringBuilder builder = new StringBuilder();try {InputStreamReader reader = new InputStreamReader(new FileInputStream(path));BufferedReader bufferedReader = new BufferedReader(reader);String tempContent = null;while ((tempContent=bufferedReader.readLine())!=null) {builder.append(tempContent);}bufferedReader.close();} catch (Exception e) {e.printStackTrace();}return filter(builder.toString());}private static String filter(String input){return input.replaceAll("/\\*[\\s\\S]*?\\*/", "");}}
0 0
- UEditor扩展上传
- 实战-Ueditor扩展二次开发
- Ueditor 上传路径修改
- ueditor 文件上传
- Ueditor JSP 图片上传
- UEditor上传图片错误
- uEditor独立图片上传
- Ueditor上传路径问题
- Ueditor上传配置
- ueditor图片上传配置
- 百度Ueditor上传插件
- UEditor图片上传
- UEDITOR FTP上传
- Ueditor上传文件配置
- UEditor上传配置
- Ueditor添加上传接口
- UEditor自定义上传
- ueditor自定义上传
- hihocoder 1191 小W与网格 (组合数)
- xml文件中,id、name的属性的区别
- Android 快速开发系列 ORMLite 框架最佳实践
- 遍历数组、数组排序
- 1089-1096
- UEditor扩展上传
- OC可变数组的创建与简单应用
- Android ORMLite 框架的入门用法
- 一个简单地Shell-like 的实现
- 第四天学习笔记
- OC中可变字典和不可变字典
- Dynamics CRM2015 The plug-in type does not exist in the specified assembly问题的解决方法
- 机房收费之查看数据库代码
- 开源 java CMS - FreeCMS2.3会员我的留言