UEditor自定义上传和读取文件路径
来源:互联网 发布:脱发知乎 编辑:程序博客网 时间:2024/05/20 06:24
1.首先在jsp中覆盖UEidtor获取路径的方法
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl; UE.Editor.prototype.getActionUrl = function(action) {if (action == 'uploadimage') {return WEBPATH+'/webCol/uploadImage';} else if (action == 'uploadvideo') {return '';} else {return this._bkGetActionUrl.call(this, action);}}
2.在springmvc配置文件中配置多文件上传
<!-- spring多文件上传 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="defaultEncoding"><value>UTF-8</value></property><property name="maxUploadSize"><!-- 上传文件大小限制为50M,50*1024*1024 --><value>52428800</value></property><!-- 内存大小限制为8M,8*1024*1024 --><property name="maxInMemorySize"><value>8388608</value></property><property name="resolveLazily" value="true"/> </bean>
3.在controller中定义上传和读取文件的方法
/** * ueditor上传图片重写 * * @param upfile * @param request * @return * @throws IOException */@RequestMapping("/uploadImage")@ResponseBody//这里upfile是config.json中图片提交的表单名称 public Map<String,String> uploadImage(@RequestParam("upfile") CommonsMultipartFile upfile,HttpServletRequest request) throws IOException{ //文件原名称String fileName=upfile.getOriginalFilename();//文件后缀名String type = fileName.substring(upfile.getOriginalFilename().lastIndexOf("."));String nowName=DateUtil.format(new Date(), "yyyyMMdd") + "_" + new Date().getTime() + type;if(!upfile.isEmpty()){ //上传位置路径String path0 = "D:\\static\\ueditor\\jsp\\upload\\image\\"+nowName;//按照路径新建文件File newFile = new File(path0);//复制FileCopyUtils.copy(upfile.getBytes(), newFile); } //返回结果信息(UEditor需要) Map<String,String> map = new HashMap<String,String >(); //是否上传成功 map.put("state", "SUCCESS"); //现在文件名称 map.put("title", nowName); //文件原名称 map.put("original", fileName); //文件类型 后缀名 map.put("type", type); //文件路径 map.put("url", "/webCol/"+nowName+"/getImage"); //文件大小(字节数) map.put("size", upfile.getSize()+""); return map;}/** * ueditor读取文件重写 */@RequestMapping("{imgName}/getImage")public void readImg(@PathVariable("imgName") String imgName, HttpServletResponse response) throws Exception { //设置文件的返回类型 response.setContentType("image/*"); //文件路径(windows下是\\,linux下是//,都必须是绝对路径) String imgPath="D:\\static\\ueditor\\jsp\\upload\\image\\"+imgName; //java中用File类来表示一个文件 File image = new File(imgPath); //测试这个文件路径是否存在(也就是这个文件是否存在) if (!image.exists()) { return; } //FileUtils.readFileToByteArray(File file)把一个文件转换成字节数组返回response.getOutputStream().write(FileUtils.readFileToByteArray(image)); //java在使用流时,都会有一个缓冲区,按一种它认为比较高效的方法来发数据://把要发的数据先放到缓冲区,缓冲区放满以后再一次性发过去,而不是分开一次一次地发.//而flush()表示强制将缓冲区中的数据发送出去,不必等到缓冲区满.response.getOutputStream().flush(); response.getOutputStream().close(); }
阅读全文
0 0
- UEditor自定义上传和读取文件路径
- UEditor图片上传文件路径
- ueditor Java版更改上传文件路径
- ueditor 更改上传文件的路径
- UEditor Java版更改上传文件路径
- ueditor Java版更改上传文件路径
- 百度UEditor图片文件改变默认保存到项目根路径,自定义上传路径或远程服务器
- ueditor上传视频控件,如何获得上传文件的路径?
- Ueditor 上传路径修改
- Ueditor上传路径问题
- ueditor上传路径问题
- 最新ueditor(1.4.3.3)版本修改自定义上传路径
- Ueditor 自定义多图上传路径及回显
- UEditor自定义上传
- ueditor自定义上传
- Ueditor 图片自定义上传
- UEditor 1.4.2+版本文件图片上传路径配置
- 百度编辑器ueditor上传图片及文件路径配置
- mysql百万级数据优化
- 移动端图片轮播?
- NumPy 便利的函数
- optee os 的启动和初始化
- android studio 插件版本太旧导致不能正常编译
- UEditor自定义上传和读取文件路径
- 随机向量
- Failure [DELETE_FAILED_INTERNAL_ERROR] 不能卸载
- DemoA
- TextView图文混排,设置部分字体背景色
- 记录c++中有用的代码
- post方式AJAX
- 北京雾霾越来越重的原因找到了!
- thinkphp中的特殊字符处理