Ueditor修改图片上传方法,Ueditor修改视频上传方法

使用Ueditor常常会需要修改图片上传的路径,甚至是视频的上传路径,进入正题:

修改ueditor.mine.js

UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
    if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage'|| action == 'uploadvideo') {
    	if(action == 'uploadvideo'){
    		 return Tool.contextPath+'/upLoadFile/ueVideo';
    	}else{
            return Tool.contextPath+'/upLoadFile/ueimg';
    	}
    } else {
        return this._bkGetActionUrl.call(this, action);
    }


}
后台接处理方法
/**
* 
* @Title: ueimg @author liuzhengwen @Description: (上传图片) @return @return
*         String 返回类型 @throws
*/
@RequestMapping("ueimg")
public void ueimg(HttpServletRequest request, HttpServletResponse response, @RequestParam("upfile") MultipartFile file, String type) {
	try {
		if (!file.isEmpty()) {
			response.setContentType("text/html");
			String fileName = file.getOriginalFilename();
			String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
			String key = uUIDWorker.getUUID() + fileSuffix;
			String url = uploadFileService.uploadImage(key, file.getBytes());
			Map data = new HashMap(0);
			if (!"".equals(url)) {
				data.put("state", "SUCCESS");
				data.put("original", file.getOriginalFilename());
				data.put("size", file.getSize() + "");
				data.put("title", url.substring(url.lastIndexOf("/") + 1, url.length()));
				data.put("type", url.substring(url.lastIndexOf("."), url.length()));
				data.put("url", url);
				response.getWriter().write(objectMapper.writeValueAsString(data));
			} else {
				data.put("state", "FAIL");
				response.getWriter().write(objectMapper.writeValueAsString(data));
			}
		}
	} catch (Exception e) {
		logger.error("=====UpLoadFileController uploadFile error================={}", e);
	}
}
注意,这里主要的是返回一个json,json中的格式如下:
{
    "state": "SUCCESS",
    "original": "1212.png",
    "size": "6253",
    "title": "892372205560730374.png",
    "type": ".png",
    "url": "http://image.zuma.com/upload/892372205560730374.png"
}
同样视频上传的方法如下:
/**
 * @throws IOException
 * 
 * @Title: ueimg @author liuzhengwen @Description: (上传图片) @return @return
 *         String 返回类型 @throws
 */
@RequestMapping("ueVideo")
public void ueVideo(HttpServletRequest request, HttpServletResponse response, @RequestParam("upfile") MultipartFile file) throws IOException {
	try {
		if (!file.isEmpty()) {
			//视频处理方法略。。。。
			JSONObject urlJson = new JSONObject();
			urlJson.put("original", imageUrl);
			String fileRealName = file.getOriginalFilename();
			urlJson.put("name", fileRealName.substring(0, fileRealName.lastIndexOf(".")));
			urlJson.put("url", url);
			urlJson.put("size", file.getSize());
			urlJson.put("type", ".flv");
			urlJson.put("state", "SUCCESS");
			// 把视频信息带到页面
			response.getWriter().write(urlJson.toJSONString());

		}
	} catch (Exception e) {
		response.getWriter().write("fail");
		logger.error("=====UpLoadFileController uploadFile error================={}", e);
	}
}

你可能感兴趣的:(Ueditor,图片上传,视频上传)