1. 程式人生 > >umeditor的jsp版本更改圖片上傳路徑的方法

umeditor的jsp版本更改圖片上傳路徑的方法

網上找了很多資料,貌似很多都不是說明的很清楚了,為了方便自己今後使用,在這裡記錄一下:

1、下載umeditor的jsp包

2、將umeditor整個放入工程自定義位置

3、將Uploader.java放到工程自定義位置

4、修改imageUp.jsp中匯入的程式碼的位置:

由原先的

<%@ page import="com.baidu.ueditor.um.Uploader" %>
修改為
<%@ page import="自定義位置.Uploader" %>

5、修改umeditor/dialogs/image/image.js

由原先的

callback: function (editor, $w, url, state) {

            if (state == "SUCCESS") {
                //顯示圖片計數+1
                Upload.showCount++;
                <span style="color:#ff6666;">var $img = $("<img src='" + editor.options.imagePath + url + "' class='edui-image-pic' />"),</span>
                    $item = $("<div class='edui-image-item edui-image-upload-item'><div class='edui-image-close'></div></div>").append($img);

                if ($(".edui-image-upload2", $w).length < 1) {
                    $(".edui-image-content", $w).append($item);

                    Upload.render(".edui-image-content", 2)
                        .config(".edui-image-upload2");
                } else {
                    $(".edui-image-upload2", $w).before($item).show();
                }

                $img.on("load", function () {
                    Base.scale(this, 120);
                    Base.close($(this));
                    $(".edui-image-content", $w).focus();
                });

            } else {
                currentDialog.showTip( state );
                window.setTimeout( function () {

                    currentDialog.hideTip();

                }, 3000 );
            }

            Upload.toggleMask();

        }
修改為
callback: function (editor, $w, url, state) {

            if (state == "SUCCESS") {
                //顯示圖片計數+1
                Upload.showCount++;
                <span style="color:#ff6666;">var $img = $("<img src='" + url + "' class='edui-image-pic' />"),</span>
                    $item = $("<div class='edui-image-item edui-image-upload-item'><div class='edui-image-close'></div></div>").append($img);

                if ($(".edui-image-upload2", $w).length < 1) {
                    $(".edui-image-content", $w).append($item);

                    Upload.render(".edui-image-content", 2)
                        .config(".edui-image-upload2");
                } else {
                    $(".edui-image-upload2", $w).before($item).show();
                }

                $img.on("load", function () {
                    Base.scale(this, 120);
                    Base.close($(this));
                    $(".edui-image-content", $w).focus();
                });

            } else {
                currentDialog.showTip( state );
                window.setTimeout( function () {

                    currentDialog.hideTip();

                }, 3000 );
            }

            Upload.toggleMask();

        }
標紅處為修改點

6、修改Uploader.java

由原有的

public void upload() throws Exception {
		boolean isMultipart = ServletFileUpload.isMultipartContent(this.request);
		if (!isMultipart) {
			this.state = this.errorInfo.get("NOFILE");
			return;
		}
		DiskFileItemFactory dff = new DiskFileItemFactory();
		String savePath = this.getFolder(this.savePath);
		dff.setRepository(new File(savePath));
		try {
			ServletFileUpload sfu = new ServletFileUpload(dff);
			sfu.setSizeMax(this.maxSize * 1024);
			sfu.setHeaderEncoding("utf-8");
			FileItemIterator fii = sfu.getItemIterator(this.request);
			while (fii.hasNext()) {
				FileItemStream fis = fii.next();
				if (!fis.isFormField()) {
					this.originalName = fis.getName().substring(fis.getName().lastIndexOf(System.getProperty("file.separator")) + 1);
					if (!this.checkFileType(this.originalName)) {
						this.state = this.errorInfo.get("TYPE");
						continue;
					}
					this.fileName = this.getName(this.originalName);
					this.type = this.getFileExt(this.fileName);
					this.url = savePath + "/" + this.fileName;
					BufferedInputStream in = new BufferedInputStream(fis.openStream());
					File file = new File(this.getPhysicalPath(this.url));
					FileOutputStream out = new FileOutputStream( file );
					BufferedOutputStream output = new BufferedOutputStream(out);
					Streams.copy(in, output, true);
					this.state=this.errorInfo.get("SUCCESS");
					this.size = file.length();
					//UE中只會處理單張上傳,完成後即退出
					break;
				} else {
					String fname = fis.getFieldName();
					//只處理title,其餘表單請自行處理
					if(!fname.equals("pictitle")){
						continue;
					}
                    BufferedInputStream in = new BufferedInputStream(fis.openStream());
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                    StringBuffer result = new StringBuffer();  
                    while (reader.ready()) {  
                        result.append((char)reader.read());  
                    }
                    this.title = new String(result.toString().getBytes(),"utf-8");
                    reader.close();  
                    
				}
			}
		} catch (SizeLimitExceededException e) {
			this.state = this.errorInfo.get("SIZE");
		} catch (InvalidContentTypeException e) {
			this.state = this.errorInfo.get("ENTYPE");
		} catch (FileUploadException e) {
			this.state = this.errorInfo.get("REQUEST");
		} catch (Exception e) {
			this.state = this.errorInfo.get("UNKNOWN");
		}
	}
修改為
public void upload() throws Exception
	{
		boolean isMultipart = ServletFileUpload.isMultipartContent(this.request);
		if (!isMultipart)
		{
			this.state = this.errorInfo.get("NOFILE");
			return;
		}
		InputStream is = null;// 附件輸入流
		try
		{
			<span style="color:#ff6666;">String path = PropertiesUtil.getProperty("picture_path_ueditor") + PropertiesUtil.getProperty("healthPic");
			String realPath = request.getSession().getServletContext().getRealPath("/") + PropertiesUtil.getProperty("picture_path") + PropertiesUtil.getProperty("healthPic");</span>
		    
		    File file = new File(realPath + File.separator);
	        // 判斷資料夾是否存在,如果不存在則建立資料夾
	        if (!file.exists()) {
	            file.mkdirs();
	        }
			MultipartResolver resolver = new CommonsMultipartResolver(
				this.request.getSession().getServletContext());
			MultipartHttpServletRequest multipartRequest = resolver.resolveMultipart(request);
			CommonsMultipartFile orginalFile = (CommonsMultipartFile) multipartRequest.getFile("upfile");
			this.originalName = orginalFile.getOriginalFilename();
			if (!this.checkFileType(this.originalName))
			{
				this.state = this.errorInfo.get("TYPE");
				return;
			}
			this.type = this.getFileExt(this.originalName);
			this.size = orginalFile.getSize();
			
			String timestamp = System.currentTimeMillis() + "";
			String newIdPicFileName = this.originalName.substring(0, this.originalName.lastIndexOf(".")) + timestamp + this.type;
            String fullName = realPath + File.separator + newIdPicFileName;
            DataOutputStream out = new DataOutputStream(new FileOutputStream(fullName));// 存放檔案的絕對路徑
            
            is = orginalFile.getInputStream();
            byte[] b=new byte[is.available()];
            is.read(b);
            out.write(b);
            
            if (is != null) {
				is.close();
			}
			if (out != null) {
				out.close();
			}
			this.url = path+newIdPicFileName;
			this.state = this.errorInfo.get("SUCCESS");
		}
		catch (Exception e)
		{
			this.state = this.errorInfo.get("UNKNOWN");
		}
	}

其中標紅的需要注意一下,path是圖片讀取的路徑,realPath是圖片檔案需要上傳到的物理路徑

7、至此已經完成

參照:http://www.w2bc.com/Article/86325



相關推薦

umeditor的jsp版本更改圖片路徑方法

網上找了很多資料,貌似很多都不是說明的很清楚了,為了方便自己今後使用,在這裡記錄一下: 1、下載umeditor的jsp包 2、將umeditor整個放入工程自定義位置 3、將Uploader.java放到工程自定義位置 4、修改imageUp.jsp中匯入的程式碼的位置:

kindedit編輯器修改圖片限制方法

圖片 編輯器 河北 修改這個編輯器的圖片上傳大小限制,有時我們修改了很多參數,都不管用,如修改multiimage.js修改了其中的上傳配置參數還是傳不上圖片 後來經過魅力網絡的測試,通過批量查找代碼查詢max_size找到一個文件upload_json.php 看見參數我在最大文件

關於富文字編輯器—UEditor(java版)的使用,以及如何將UEditor的檔案/圖片路徑改成絕對路徑

突然發現好久沒寫部落格了,感覺變懶了,是要讓自己養成經常寫文章的習慣才行。既可以分享自己的所學,和所想,和大家一起討論,發現自己的不足的問題。 大家可能經常會用到富文字編輯器,今天我要說的是UEditor的使用,這是一個簡單易用的開源富文字編輯器。但是對於沒有用過的同學而言還是需要稍微瞭解一下的。 可能有些人

改變dede圖片路徑(商品-縮圖)去掉/allimg/ymd/

include\common.inc.phpline185://上傳的普通圖片的路徑,建議按預設//lyy $cfg_image_dir = $cfg_medias_dir.'/allimg';$cfg

建立 Js圖片實現方法總結

$(function(){     $("#file_upload").uploadify({         'auto':true,        //是否為自動上傳         'swf':'/uploadify/uploadify.swf',     //上傳的flash外掛         'u

KindEditor圖片路徑URL的處理

最近的專案中使用了KindEditor作為富文字編輯器進行文字編輯處理。KindEditor 是一套開源的線上HTML編輯器,主要用於讓使用者在網站上獲得所見即所得編輯效果,開發人員可以用 KindEditor 把傳統的多行文字輸入框(textarea)替換為視覺化的富文

FCK 編輯器 圖片路徑修改

修改路徑 include\fck\editor\filemanager\connectors\php\config.php 修改地方 $Config['UserFilesPath'] = QFWEB.'eng/uploads/' ;

百度Ueditor 圖片路徑配置

找到php資料夾中的config.json檔案,修改其中的imagePathFormat屬性  "imagePathFormat": "/blog/Data/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", 

Ueditor自定義圖片路徑,以及圖片回顯路徑

最近發現Ueditor有個小bug,每次圖片都上傳到專案路徑下,當重新發佈一個版本後,圖片就沒了,所以決心修改結構如下:1. 首先,進入config.json,修改如下:其他的都不改,只改選中部分,這個是圖片訪問路徑字首我們要關注的是【檔案訪問路徑】和【檔案上傳路徑】然後,分

multipart/form-data圖片實現方法(檔案到Nimg)

        在實現multipart/form-data的圖片上傳時,需要用\r\n來分隔每一行,在JAVA中實現multipart/form-data的圖片上傳時則可以使用System.getProperty("line.separator")來進行每一行的分割。但是如果要將程式碼用於Android中

django 自定義圖片路徑檔名

圖片上傳中,如果不對上傳的檔名做處理,很容易引起檔名重複,這會覆蓋之前上傳的圖片,django提供了自定義上傳檔名的方法。 def generate_filename(self, instance, filename): """ Ap

ueditor前後端分離下的圖片解決方法

一個小專案,簡稱(A專案),因為是做的前後端分離,後端用spring boot打的jar包,前端需要用到ueditor儲存圖片,搞了好久沒搞出來,網上查到的大部分都是對原始碼進行修改的,對於一個新手來說太過高階,根據公司一位前輩的方法,可以先在伺服器上增加一個ueditor

wangeditor圖片方法簡單例項

js部分 <script type="text/javascript"> var E = window.wangEditor var editor = new E('#editor'); editor.

ueditor 圖片路徑配置

ueditor的圖片上傳路徑配置檔案是 ueditor/php/config.json 以下是我遇到的一些因為ueditor預設設定引起的圖片上傳路徑配置的問題,特此拿出來與大家分享,如果有說

富文字編輯器圖片功能提示falsh版本低請你升級的解決方法

1,最好先檢查下瀏覽器的falsh是否禁用如禁用需開啟 2,安裝官網falsh並重新打卡瀏覽器 falsh禁用會導致很多外掛用不了(圖片上傳外掛,編輯器外掛,視訊播放功能等), 程式碼執行中找不到錯誤,

django admin圖片更改路徑圖片名稱

今天終於學會了 django admin 上傳圖片更改路徑和圖片名稱; 廢話不說 ,步驟開始。 1.自定義 上傳圖片的儲存路徑和,圖片名稱格式。 def upload_path_handler(instance, filename):     filename="ewn1.

IE8升級新版Flash Player ActiveX14導致的discuz圖片附件無法 解決方法

forum rgb 百度快照 orm 顯示 img 全部 百度 文件上傳 之前發的這篇文章被編輯之後丟失了。無奈從百度快照找來又一次公布。不知道csdn抽啥風 架不住sb adobe的頻繁升級提示,手欠升級到了了flash player 14,

CKEditor實現圖片,並且回調圖片路徑

js文件 文件上傳 hid class mode 兩種方法 review 重名 action CKEditor編輯器的工具欄中初始的時候應該是這樣子的,沒有圖片上傳按鈕 並且預覽中有一堆火星文,可以修改相應配置刪除它。 第一種方法:打開ckeditor/plugins/im

修改帝國CMS默認圖片附件路徑

load 默認 行修改 方法 需要 想要 成功 教程 左右 帝國CMS系統設置中的“附件地址”設置是不生效的,無論設置成什麽都還是在 d/file/ 下,下面牛教程介紹手動修改附件存放地址的方法。 一:先在系統設置中將“附件地址”一項修改為自己想要的地址,這裏以 /uplo

使用canvas給圖片添加水印, canvas轉換base64,,canvas,圖片,base64等轉換成二進制文檔流的方法,並將合成的圖片到服務器,

web don 可能 work box rac return ros font 一,前端合成帶水印的圖片 一般來說,生成帶水印的圖片由後端生成,但不乏有時候需要前端來處理。當然,前端處理圖片一般不建議,一方面js的處理圖片的方法不全,二是有些老版本的瀏覽器對canvas