您的位置:首页 > 产品设计 > UI/UE

[置顶] Ueditor修改图片上传方法,Ueditor修改视频上传方法

2017-08-01 20:54 337 查看
使用Ueditor常常会需要修改图片上传的路径,甚至是视频的上传路径,进入正题:

修改ueditor.mine.jsUE.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<String, Object> data = new HashMap<String, Object>(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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: