关于uEditor,上传图片到指定主机(图片服务器)

jsp、html中如下:

	


在js中如下:

UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action){
    	//调用自己写的Controller
    	if(action == 'uploadimage' || action == 'uploadfile'){
    		return "${ctx}/ueditor/imageUp"; //自己controller的action
    	}else if(action == "uploadvideo"){
    		return "${ctx}/ueditor/videoUp";//自己controller的action
    	}else{
    		return this._bkGetActionUrl.call(this,action);//百度编辑器默认的action
    	}
    }
	var ue = UE.getEditor('editor');

自己的controller:   ueEditor会将图片、视频传到自定义的controller中,再处理就OK了。

package com.pd.*****.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.pd.***.entity.URlAndPath;
import com.pd.***.util.FileUploadUtils;
import com.pd.***.utils.PropertiesUtils;
/**
 * Ue便捷器文件上传Controller
 * @author guoxinming
 * @date  2017-07-18
 */  
@Controller  
@RequestMapping("/ueditor")  
public class UeditorController {  
    /**
     * 上传图片到图片服务器
     * @param file 上传文件流
     * @param request 请求域
     * @return String 返回JSON数据
     */
	@RequestMapping(value="/imageUp" ,produces = {"application/json;charset=UTF-8"})
    @ResponseBody  
    public String fileUp(@RequestParam(value = "upfile", required = false) MultipartFile file, HttpServletRequest request) {
		Map result = new HashMap();
		String url=PropertiesUtils.getProperty("IMAGE_UPLOAD_ROOT")+PropertiesUtils.getProperty("NEWS_PICTURE_PATH")+"/";
		result=fileUpToServer(file,url);
		return JSON.toJSONString(result); 
    }  
	/**
     * 上传视频到服务器
     * @param file 上传文件流
     * @param request 请求域
     * @return String 返回JSON数据
     */
	@RequestMapping(value="/videoUp" ,produces = {"application/json;charset=UTF-8"})
    @ResponseBody  
    public String videoUp(@RequestParam(value = "upfile", required = false) MultipartFile file, HttpServletRequest request) {
		Map result = new HashMap();
		String url=PropertiesUtils.getProperty("IMAGE_UPLOAD_ROOT")+PropertiesUtils.getProperty("NEWS_VIDEO_PATH")+"/";
		result=fileUpToServer(file,url);
		return JSON.toJSONString(result); 
    }  
	/**
	 * 上传文件到服务器
	 * @param file
	 * @param  url 文件上传服务器的路径
	 * @return Map 对应的文件回显数据
	 */
	public Map fileUpToServer(MultipartFile file,String url){
		String fileName = file.getOriginalFilename();// 获得上传文件的实际名称
		String[] types = fileName.split("\\.");
		String type = types[types.length - 1];
		type = "." + type;// 获得文件的后缀名

		List list = new ArrayList();
		FileUploadUtils.uploadPic(file, list, url);

		Map result = new HashMap();
		result.put("state", "SUCCESS");// UEDITOR的规则:不为SUCCESS则显示state的内容
		result.put("url", list.get(0).getUrl());
		result.put("title", file.getOriginalFilename());
		result.put("original", file.getOriginalFilename());
		result.put("size", file.getSize());
		result.put("type", type);
		return result;
	}
}  


你可能感兴趣的:(文本编辑器)