jquery檔案批量上傳控制項Uploadify3.2(java springMVC)

來源:互聯網
上載者:User

標籤:static   origin   context   檔案的   getname   取消   eid   類的方法   背景   

人比較懶  有用為主 不怎麼排版了


先放上Uploadify的官網連結:http://www.uploadify.com/  -->裡面能夠看到PHP的示範範例,屬性說明,以及控制項。分flash版(免費)和html5版(收費)。

官網上能夠看到效果示範。


另外在網上找到了一份Uploadify3.2的中文API文檔。能夠在我上傳的資源裡面下載。


以下就是一個基於springMVC的檔案上傳示範範例,看起來可能比文檔更直觀一些···


1.下載外掛程式放到項目中


2.在jsp頁面中引入下面JS和CSS

<script type="text/javascript" src="${ctxStatic}/uploadify/jquery.uploadify.min.js"></script><link type="text/css" rel="stylesheet" href="${ctxStatic}/uploadify/uploadify.css">

3.jsp頁面中建立展示DIV和操作button

</pre><pre name="code" class="html"><form><div id="queue"></div><!-上傳隊列展示區--><input id="file_upload" name="file_upload" type="file" multiple="true"><!-批量上傳button--></form>

4.編輯js代碼

$(document).ready(function() {$("#file_upload").uploadify({‘swf‘ : ‘${ctxStatic}/uploadify/geo_fileUpload.swf‘,//控制項flash檔案位置                        //幕後處理的請求(也就是action請求路徑),後面追加了jsessionid,用來標示使用當前session(預設是開啟新的session。會導致存在session校正的請求中產生302錯誤)                        ‘uploader‘ : ‘${ctx}/testFu;jsessionid=${pageContext.session.id}‘,‘queueID‘ : ‘queue‘,//與以下HTML的div.id相應  ‘width‘ : ‘100‘,//button寬度‘height‘ : ‘32‘,//button高度‘fileTypeDesc‘ : ‘指定類型檔案‘,‘fileTypeExts‘ : ‘*.jpg;*.png‘, //控制可上傳檔案的副檔名,啟用本項時需同一時候聲明fileDesc ‘fileObjName‘ : ‘myTestFile‘,//檔案對象名稱,用於後台擷取檔案對象時使用,詳見以下的java代碼‘buttonText‘ : ‘批量上傳‘,//上傳button顯示內容。還有個屬效能夠設定button的背景圖片‘fileSizeLimit‘ : ‘100KB‘,‘multi‘ : true,‘overrideEvents‘ : [ ‘onDialogClose‘, ‘onUploadSuccess‘, ‘onUploadError‘, ‘onSelectError‘ ],//重寫預設方法‘onFallback‘ : function() {//檢測FLASH失敗調用alert("您未安裝FLASH控制項。無法上傳圖片!請安裝FLASH控制項後再試。

");}, //以下方法是相應overrideEvents的重載方法,詳細實現是網上找到的一個別的朋友的代碼, //我把這些方法抽到了一個自己定義js中。我會在最後面貼出來 ‘onSelect‘ : uploadify_onSelect,‘onSelectError‘ : uploadify_onSelectError,‘onUploadError‘ : uploadify_onUploadError,‘onUploadSuccess‘ : uploadify_onUploadSuccess});});

5.controller類的方法

<pre name="code" class="html">@ResponseBody@RequestMapping(value = "testFu")
        //這裡的<span style="font-family: Arial, Helvetica, sans-serif;">creativeFile與上面jsp空間中的</span><span style="font-family: Arial, Helvetica, sans-serif;">creativeFile相應</span><span style="font-family: Arial, Helvetica, sans-serif;"></span>public String testUpload(MultipartFile creativeFile, HttpServletResponse response) {System.out.println(creativeFile.getName());System.out.println(creativeFile.getOriginalFilename());System.out.println(creativeFile.getSize());return "測試測試";// 返回給前台的提示資訊}

6.附錄摘自網上的重載方法列表,我做了一些修改使之更有用(感謝網路無名高手)

var uploadify_onSelectError = function(file, errorCode, errorMsg) {var msgText = "上傳失敗\n";switch (errorCode) {case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:// this.queueData.errorMsg = "每次最多上傳 " +// this.settings.queueSizeLimit + "個檔案";msgText += "上傳的檔案數量已經超出系統限制的" + $(‘#file_upload‘).uploadify(‘settings‘, ‘queueSizeLimit‘) + "個檔案!";break;case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:msgText += "檔案 [" + file.name + "] 大小超出系統限制的" + $(‘#file_upload‘).uploadify(‘settings‘, ‘fileSizeLimit‘) + "大小。";break;case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:msgText += "檔案大小為0";break;case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:msgText += "檔案格式不對,僅限 " + this.settings.fileTypeExts;break;default:msgText += "錯誤碼:" + errorCode + "\n" + errorMsg;}alert(msgText);};var uploadify_onUploadError = function(file, errorCode, errorMsg, errorString) {// 手工取消不彈出提示if (errorCode == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED || errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {return;}var msgText = "上傳失敗\n";switch (errorCode) {case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:msgText += "HTTP 錯誤\n" + errorMsg;break;case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:msgText += "上傳檔案丟失,請又一次上傳";break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:msgText += "IO錯誤";break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:msgText += "安全性錯誤\n" + errorMsg;break;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:msgText += "每次最多上傳 " + this.settings.uploadLimit + "個";break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:msgText += errorMsg;break;case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:msgText += "找不到指定檔案。請又一次操作";break;case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:msgText += "參數錯誤";break;default:msgText += "檔案:" + file.name + "\n錯誤碼:" + errorCode + "\n" + errorMsg + "\n" + errorString;}alert(msgText);}var uploadify_onSelect = function() {};var uploadify_onUploadSuccess = function(file, data, response) {alert("儲存每一個檔案上傳後台返回的相關資訊,在onQueueComplete方法中展示");};var uploadify_onQueueComplete = function(){alert("所有完畢-->並展示提示資訊");}

到此Uploadify的檔案批量上傳就OK了。 有疑問能夠留言咱們一起討論。這個控制項非常easy花時間看的話都能弄懂。寫這個文章的目的也是為了讓大家更快上手。節省寶貴時間




jquery檔案批量上傳控制項Uploadify3.2(java springMVC)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.