檔案非同步上傳,多檔案上傳外掛程式uploadify

來源:互聯網
上載者:User

標籤:blog   http   io   os   使用   sp   java   strong   on   

本文中使用java作為例子

uploadify下載 http://files.cnblogs.com/chyg/uploadify.zip

jsp頁面中需要引入:

<script type="text/javascript" src="jquery.uploadify.js"></script>

  

主要js代碼:

$("#sysLogo").uploadify({                    ‘uploader‘: ‘${ctx}/web/module/config/configupload/uploadSysLog.action‘,//檔案上傳action                  //  ‘script‘: ‘${ctx}/web/module/config/configupload/uploadSysLog.action‘,                  ‘swf‘      : ‘uploadify.swf‘,                    ‘cancelImg‘: ‘cancel.png‘,                    ‘folder‘: ‘UploadFile‘,                    ‘queueID‘: ‘fileQueue‘, //上傳隊列id                    ‘fileObjName‘ : ‘sysLogoFiles‘, //後台擷取的檔案名稱,                    ‘auto‘: true,//是否自動上傳                    ‘multi‘: true, //是否支援多選                    ‘onUploadSuccess‘ : function(file, data, response) { //上傳成功後執行                    alert("sucess");                     console.log(file);                    console.log("data:"+data);                    }                });

//註:上面只是部分參數,uploadify還有很多參數,具體請自動搜尋api

  

jsp頁面:

                    <div class="controls">                        <input type="file" id="sysLogo" name="sysLogoFile" >                        <div id="fileQueue"></div>                    </div>

 java代碼:

public void uploadSysLog() throws IOException{System.out.println(sysLogoFiles);  //sysLogoFiles為全域變數,List<File>OutputStream fileOutputStream = null;InputStream in = null;File file = new File("d:/abc.jpg"); // 建立檔案try {fileOutputStream = new FileOutputStream(file); // 建立檔案流in = new FileInputStream(sysLogoFiles.get(0));int bytesRead = 0;byte data[] = new byte[1024 * 1024]; // 用於存放流資料while ((bytesRead = in.read(data)) > 0) {fileOutputStream.write(data, 0, bytesRead); // 寫入檔案流}} catch (RuntimeException e) {e.printStackTrace();} finally {if (fileOutputStream != null) {fileOutputStream.close();fileOutputStream = null;}if (in != null) {in.close();in = null;}}getResponse().getWriter().write("uploadify-cancel.png");//返回到頁面的資料,此處隨便返回一個圖片路徑}

 

 以上即可。

 

檔案非同步上傳,多檔案上傳外掛程式uploadify

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.