ueditor uft-8 jsp版本配置

来源:互联网 发布:淘宝旗袍第一模特 编辑:程序博客网 时间:2024/05/22 13:33

1.前台html:

<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>

var ue = UE.getEditor('editor');

<script type="text/javascript">
      UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
      UE.Editor.prototype.getActionUrl = function(action) {
          if (action == '/fileUpload/imgUpload') {
              return 'http://127.0.0.1:8084/demo/fileUpload/imgUpload';
          } else {
              return this._bkGetActionUrl.call(this, action);
          }
      }
    </script>


2.jsp/config.json

/* 上传图片配置项 */
    "imageActionName": "/fileUpload/imgUpload", /* 执行上传图片的action名称 */
    "imageFieldName": "upfile", /* 提交的图片表单名称 */
    "imageMaxSize": 2048000, /* 上传大小限制,单位B */
    "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
    "imageCompressEnable": true, /* 是否压缩图片,默认是true */
    "imageCompressBorder": 1600, /* 图片压缩最长边限制 */
    "imageInsertAlign": "none", /* 插入的图片浮动方式 */
    "imageUrlPrefix": "", /* 图片访问路径前缀 */
    "imagePathFormat": "/ueditor/jsp/upl


java后台上传图片到ftp:

@ResponseBody
@RequestMapping(value = "/imgUpload", method = { RequestMethod.GET,
RequestMethod.POST })
public String imgUpload(HttpServletRequest request,
HttpServletResponse response,@RequestParam("upfile") MultipartFile[] files) throws IllegalStateException,
IOException {
response.setContentType("text/html;charset=UTF-8");

ReturnUploadImage rui = null;
final List<ReturnUploadImage> ruiList = new ArrayList<ReturnUploadImage>();
for (final MultipartFile file : files) {

// 当前上传文件的文件名称
String fileName = file.getOriginalFilename();
// 当前上传文件的文件类型
String fileType = file.getContentType();
// 当前上传文件的文件大小
Long fileSize = file.getSize();
// 当前上传文件的文件后缀
String suffix = fileName.indexOf(".") != -1 ? fileName
.substring(fileName.lastIndexOf("."),
fileName.length()) : null;
// 重命名上传后的文件名
String saveFileName = UUID.randomUUID() + suffix;
// 定义上传路径
String savePath = "/uploadCloud" + "/" + saveFileName;
FTPClientTemplate ftp = new FTPClientTemplate();
ftp.setHost(FtpConfigUtil.getHOST());
ftp.setPort(FtpConfigUtil.getPORT());
ftp.setUsername(FtpConfigUtil.getUsername());
ftp.setPassword(FtpConfigUtil.getPassword());
ftp.setBinaryTransfer(false);
ftp.setPassiveMode(false);
ftp.setEncoding("utf-8");
boolean ret = ftp.put(savePath, file.getInputStream(),
savePath);

rui = new ReturnUploadImage();// 这个是UEditor需要的返回值内容,UEditor要的返回值需要封装成Json格式
rui.setTitle(fileName);
rui.setOriginal(fileName);
rui.setState("SUCCESS");
rui.setUrl("http://111.231.110.149:8081/FTPfile/uploadCloud/"
+ saveFileName);
// rui.setUrl(savePath);
ruiList.add(rui);

}

String result = JSON.toJSONString(rui);// 这边就是为了返回给UEditor做的格式转换
response.getWriter().write(result);
return null;
}

原创粉丝点击