jfinal框架ueditor上传图片的实现方法

7 篇文章 0 订阅
4 篇文章 0 订阅
使用ueditor编辑器大大方便了我们的开发,下面我说一下在使用ueditor上传图片的java方法实现:
public void uploadImage() {
		List<UploadFile> fileList = getFiles( PathKit.getWebRootPath()+ RESOURCE_DIR);
		String imgpath =PathKit.getWebRootPath() + RESOURCE_DIR+"/";
		String title = "";
		String fname = "";
		String newFileName = "";
		String state = "SUCCESS";
		if (fileList != null && fileList.size() > 0) {
			UploadFile file = (UploadFile) fileList.get(0);
			UploadFile f = (UploadFile) file;
			// 获取文件名
			fname = f.getFileName();
			// 获取的是.jpg
			String suwf = fname.substring(fname.lastIndexOf("."),
					fname.length());
			// 随机生成的
			newFileName = fileUtil.getNewFileName(fname);
			f.getFile().renameTo(new File(imgpath + newFileName));
			try {
				File file1 = new File(imgpath + newFileName);
				Iterator<ImageReader> readers = ImageIO
						.getImageReadersByFormatName(suwf.substring(1,
								suwf.length()));
				ImageReader reader = (ImageReader) readers.next();
				ImageInputStream iis = ImageIO.createImageInputStream(file1);
				reader.setInput(iis, true);
				iis.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			// 实际上是原图片名
			title = getPara("pictitle");
			if (title == null || title.trim().length() == 0) {
				title = fname;
			}
		} else {
			state = "";
		}
		title = title.replace("&", "&").replace("'", "&qpos;")
				.replace("\"", """).replace("<", "<")
				.replace(">", ">");
		renderText("{'original':'" + fname + "','url':'http://"
				+ getRequest().getServerName() + ":"
				+ getRequest().getServerPort() + getRequest().getContextPath()
				+ RESOURCE_DIR+"/" + newFileName + "','title':'" + title
				+ "','state':'" + state + "'}");
	}





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值