ipu的trunk版的android工程和服务端工程。

uploaddownload.js 1.8KB

    require(["domReady!","wadeMobile", "util"], function(doc,WadeMobile) { var iscroll = new iScroll("content"); var picDir = "picture"; /*选择图片*/ $("#getPicture").tap(function() { WadeMobile.getPicture(function(filePath){ $("#uploadFilePath").html(filePath); }); }); //上传 $("#upload").tap(function() { var uploadFile = $("#uploadFilePath").html(); if(!uploadFile){ alert("请先选择上传文件!"); return; } /*单文件上传*/ var params = Wade.DataMap(); params.put("FILE_PATH",picDir); //服务端SESSION_ID不能为空,服务端配置verify="false"并不校验 params.put("SESSION_ID",new Date().getTime()); WadeMobile.uploadWithServlet(uploadFile, "UploadDownloadBean.upload", params.toString(), function(result){ alert(result); var data = new Wade.DataMap(result); alert(data); $("#fileUpload").html(data.get("FILE_NMAE")); }); /*多文件上传*/ //有待补充 }); //下载 $("#download").tap(function() { //文件保存路径 var savePath = picDir+"/my.png"; //支持绝对路径和相对路径 var params = new Wade.DataMap(); params.put("FILE_PATH", picDir);//下载文件的相对路径 //服务端SESSION_ID不能为空,服务端配置verify="false"并不校验 params.put("SESSION_ID",new Date().getTime()); WadeMobile.downloadWithServlet(savePath, "UploadDownloadBean.download", params.toString(), function(result){ $("#downloadFilePath").html(savePath); /*var width = $("#downloadPicture").width(); var height = $("#downloadPicture").height(); $("#downloadPicture").removeClass("e_imagePlaceHolder"); $("#downloadPicture").html("<img height='" + height + "' width='" + width + "' src='" + path + "'/>"); iscroll.refresh();*/ alert(result); }); }); });