百度富文本图片上传路径配置(非项目路径)
来源:互联网 发布:爱淘宝买东西如何返利 编辑:程序博客网 时间:2024/06/05 01:52
一、前言
在项目中使用了百度富文本,发现图片上传的路径是项目的路径,但是现在要求将图片存储在项目之外的地方,如D:/ 盘等,按照API配置貌似无法做到这个要求,那么就需要稍微修改源码了,以下是本人解决方案,仅供参考
二、解决方案
前提是已经引入百度富文本,并且能够正常使用,若还无法正常使用,请阅读API
第一步:新建ActionEnterPlugs 并继承ActionEnter(com.baidu.ueditor包内)
import com.baidu.ueditor.ActionEnter;import com.baidu.ueditor.ConfigManager;import com.baidu.ueditor.define.ActionMap;import com.baidu.ueditor.define.BaseState;import com.baidu.ueditor.define.State;import com.baidu.ueditor.hunter.FileManager;import com.baidu.ueditor.hunter.ImageHunter;import com.baidu.ueditor.upload.Uploader;import java.util.Map;import javax.servlet.http.HttpServletRequest;/** * 重写百度富文本类,使其具有存储非项目路径 * Created by 韩信 on 2017-12-18. */public class ActionEnterPlugs extends ActionEnter { private HttpServletRequest request = null; private String rootPath = null; private String contextPath = null; private String actionType = null; private ConfigManager configManager = null; //图片存储路径 private String saveRootPath; public ActionEnterPlugs(HttpServletRequest request, String rootPath,String saveRootPath){ super(request,rootPath); this.request = request; this.rootPath = rootPath; this.actionType = request.getParameter("action"); this.contextPath = request.getContextPath(); this.configManager = ConfigManager.getInstance(this.rootPath, this.contextPath, request.getRequestURI()); this.saveRootPath = saveRootPath; } @Override public String invoke() { if(this.actionType != null && ActionMap.mapping.containsKey(this.actionType)) { if(this.configManager != null && this.configManager.valid()) { State state = null; int actionCode = ActionMap.getType(this.actionType); Map<String, Object> conf = null; switch(actionCode) { case 0: return this.configManager.getAllConfig().toString(); case 1: case 2: case 3: case 4: conf = this.configManager.getConfig(actionCode); //重点,这里修改了图片的存储路径 conf.put("rootPath",this.saveRootPath); state = (new Uploader(this.request, conf)).doExec(); break; case 5: conf = this.configManager.getConfig(actionCode); //重点,这里修改了图片的存储路径 conf.put("rootPath",this.saveRootPath); String[] list = this.request.getParameterValues((String)conf.get("fieldName")); state = (new ImageHunter(conf)).capture(list); break; case 6: case 7: conf = this.configManager.getConfig(actionCode); //重点,这里修改了图片的存储路径 conf.put("rootPath",this.saveRootPath); int start = this.getStartIndex(); state = (new FileManager(conf)).listFile(start); } return state.toJSONString(); } else { return (new BaseState(false, 102)).toJSONString(); } } else { return (new BaseState(false, 101)).toJSONString(); } }}第二步:找到controller.jsp文件,并修改为
<%@ page language="java" contentType="text/html; charset=UTF-8"import="com.baidu.ueditor.ActionEnter" pageEncoding="UTF-8"%><%@ page import="com.xjkj.baidu.ueditor.plugs.ActionEnterPlugs" %><%@ page import="com.xjkj.common.util.PropertiesFileUtil" %><%@ page trimDirectiveWhitespaces="true" %><% request.setCharacterEncoding( "utf-8" );response.setHeader("Content-Type" , "text/html");String rootPath = application.getRealPath( "/" );//文件存储路径,可以读取配置文件String saveRootPath = PropertiesFileUtil.getInstance().get("SYSTEM_UPLOAD_IMAGE");//获取图片路径前缀,可以读取配置文件//String getFilePath = PropertiesFileUtil.getInstance().get("SYSTEM_DOWN_IMAGE");String action = request.getParameter("action");//重点在这里,使用ActionEnterPlugs我们刚在新建的类String result = new ActionEnterPlugs( request, rootPath ,saveRootPath).exec();if( action!=null && (action.equals("listfile") || action.equals("listimage") ) ){rootPath = saveRootPath.replace("\\", "/");result = result.replaceAll(saveRootPath, "/");}//result = result.replaceAll("/file",getFilePath);out.write( result );%>
到此已经修改完毕,现在图片已经存储在你配置文件中配置的存储路径。
阅读全文
0 0
- 百度富文本图片上传路径配置(非项目路径)
- 百度富文本编辑器的上传图片的路径问题
- 百度富文本编辑器的上传图片的路径问题
- 百度富文本编辑器的上传图片的路径问题
- 百度富文本编辑器的上传图片的路径问题
- 百度富文本编辑器的上传图片的路径问题
- 百度富文本编辑器的上传图片的路径问题
- 百度富文本编辑器的上传图片的路径问题
- 百度ueditor富文本--图片保存路径的配置以及上传到远程服务器
- kindeditor富文本上传图片路径
- 百度ueditor富文本--配置图片上传
- 百度Ueditor 图片上传路径配置
- 百度富文本控件UEditor 上传图片
- 百度Ueditor富文本编辑器上传图片
- 百度富文本编辑器(ueditor)自定义上传接口(路径)
- 百度富文本编辑器 UEditor 1.4.3 自定义图片保存路径
- 百度编辑器ueditor上传图片及文件路径配置
- 百度ueditor编辑器将图片上传到非项目根路径(保存在磁盘上)或独立服务器解决方案
- 使用jquery在页面上加sidebox
- java ++i, i++,--i ,i--区别
- logstic回归损失函数及梯度下降公式推导
- 关于ViewDragHelper动态addview的问题
- Mac:TexStudio environ not found
- 百度富文本图片上传路径配置(非项目路径)
- soket相关
- QT下添加字库支持
- [ BSGS ] BZOJ3239
- Caffe入门学习(7)将自己的图像数据转成lmdb格式
- JS实现用户上传图片并预览(图片fakepath问题)
- js(三)---函数的作用域与闭包
- Android多线程--Android中常见的四种线程池
- c语言中的结构体