云存储文件下载功能_第1页
云存储文件下载功能_第2页
云存储文件下载功能_第3页
云存储文件下载功能_第4页
云存储文件下载功能_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

云存储文件下载功能目录技术原理实现步骤功能描述功能测试2技术原理3(1)视图层:显示文件下载界面(2)控制层:接收视图层的消息,向服务层发送文件下载参数(3)服务层:调用swift提供的下载接口实现文件下载功能描述4实现步骤5在cn/edu/sict/cloud/storage/service/SwiftStorageService.java添加如下代码public

byte[]download(Stringusername,Stringpath){SwiftDFSswiftdfs=newSwiftDFS();return

swiftdfs.downloadFile(username+"/"+path);}实现步骤6在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码public

byte[]downloadFile(Stringrpath){Mapmappath=this.getSplitPath(rpath);StringrootPath=mappath.get("rootPath").toString();Stringpath=mappath.get("path").toString();DLPayloaddl=os.objectStorage().objects().download(rootPath,path);InputStreamip=dl.getInputStream();byte[]in_b=null;ByteArrayOutputStreamswapStream=newByteArrayOutputStream();byte[]buff=new

byte[100];int

rc=0;实现步骤7在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代码try{while((rc=ip.read(buff,0,100))>0){swapStream.write(buff,0,rc);}in_b=swapStream.toByteArray();swapStream.close();ip.close();}catch(IOExceptione){e.printStackTrace();}return

in_b;}实现步骤8在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码@RequestMapping("/download")public

voiddownload(HttpServletRequestrequest,HttpServletResponseresponse,Stringpaths){try{String[]strs=paths.split(",");int

len=strs.length;if(len<1){return;}Useruser=getSessionUser(request);response.setContentType("text/html;charset=UTF-8");request.setCharacterEncoding("UTF-8");BufferedInputStreambis=null;BufferedOutputStreambos=null;实现步骤9在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码Stringpath=request.getSession().getServletContext().getRealPath("/");StringctxPath=path+"export";if(len==1){Stringfilepath=strs[0];//(String)map.get("path");filepath=UtilTools.converStr(filepath);byte[]b=new

byte[]{};实现步骤10在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码if(storage

instanceofSwiftStorageService){b=((SwiftStorageService)storage).download(user.getUsername(),filepath);}if(storage

instanceofHadoopStorageService){String[]strsss=filepath.split("/");Stringfilename=strsss[strsss.length-1];StringdownLoadPath=ctxPath+File.separator+filename;((HadoopStorageService)storage).download(filepath,downLoadPath);}实现步骤11在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码String[]strsss=filepath.split("/");Stringfilename=strsss[strsss.length-1];StringdownLoadPath=ctxPath+File.separator+filename;FiledownLoadFile=newFile(downLoadPath);downLoadFile.createNewFile();BufferedOutputStreambuffer=newBufferedOutputStream(newFileOutputStream(downLoadFile));实现步骤12在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码buffer.write(b);buffer.flush();buffer.close();long

fileLength=downLoadFile.length();response.setContentType("application/octet-stream");response.setHeader("Content-disposition","attachment;filename="+newString(filename.getBytes("utf-8"),"ISO8859-1"));response.setHeader("Content-Length",String.valueOf(fileLength));bis=newBufferedInputStream(newFileInputStream(downLoadPath));实现步骤13在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码bos=newBufferedOutputStream(response.getOutputStream());byte[]buff=new

byte[2048];int

bytesRead;while(-1!=(bytesRead=bis.read(buff,0,buff.length))){bos.write(buff,0,bytesRead);}bis.close();bos.close();downLoadFile.delete();}else{实现步骤14在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码String[]strss=strs[0].split("/");Stringtemps=strss[strss.length-1];String[]strr=temps.split("\\.");strr[0]=UtilTools.converStr(strr[0]);Stringrootname=ctxPath+File.separator+strr[0];Filerfile=newFile(rootname);rfile.mkdir();for(int

i=0;i<len;i++){Stringfilepath=strs[i];//(String)map.get("path");filepath=UtilTools.converStr(filepath);byte[]b=new

byte[]{};if(storage

instanceofSwiftStorageService){b=((SwiftStorageService)storage).download(user.getUsername(),filepath);}实现步骤15在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码if(storage

instanceofHadoopStorageService){String[]strsss=filepath.split("/");Stringfilename=strsss[strsss.length-1];Stringdpath=rootname+File.separator+filename;((HadoopStorageService)storage).download(filepath,dpath);continue;}String[]strsss=filepath.split("/");Stringfilename=strsss[strsss.length-1];Stringdpath=rootname+File.separator+filename;Filedfile=newFile(dpath);dfile.createNewFile();实现步骤16在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码BufferedOutputStreambuff=newBufferedOutputStream(newFileOutputStream(dfile));buff.write(b);buff.flush();buff.close();}Filetarfile=newFile(rootname+".zip");tarfile.createNewFile();UtilTools.WriteToTarGzip(ctxPath+File.separator,strr[0],strr[0]+".zip");StringdownLoadPath=rootname+".zip";Stringfp="[批量下载]"

+strr[0]+".zip";FiledownLoadFile=newFile(downLoadPath);long

fileLength=downLoadFile.length();实现步骤17在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码response.setContentType("application/octet-stream");response.setHeader("Content-disposition","attachment;filename="+newString(fp.getBytes("utf-8"),"ISO8859-1"));response.setHeader("Content-Length",String.valueOf(fileLength));bis=newBufferedInputStream(newFileInputStream(downLoadPath));bos=newBufferedOutputStream(response.getOutputStream());byte[]buff=new

byte[2048];int

bytesRead;实现步骤18在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代码while(-1!=(bytesRead=bis.read(buff,0,buff.length))){bos.write(buff,0,bytesRead);}bis.close();bos.close();downLoadFile.delete();UtilTools.deletefile(rootname);}}catch(Exceptione){e.printStackTrace();}}实现步骤19为下载按钮绑定单击事件downloadfile():functiondownloadfile(){varobjTable=document.getElementById("tab");vardata='';for(vary=0;y<objTable.rows.length;y++){varcheckbox=objTable.rows[y].childNodes[1].childNodes[0].childNodes[5];if(checkbox.checked==true){vartd3=checkbox.parentNode.parentNode.parentNode.childNodes[3];Varimgpic=td3.getElementsByTagName(“img”);If(imgpic.length>0){Alert("文件夹中内

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论