-
-
Save evsapi/2509845 to your computer and use it in GitHub Desktop.
IDrive - EVS - REST API - downloadFile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Parameters to download/restore the latest version | |
| String params="uid="+strUsername+"&pwd="+strPassword+"&pvtkey="+strKey+"&p="+strPath; | |
| // Parameters to download/restore specified version | |
| String params="uid="+strUsername+"&pwd="+strPassword+"&pvtkey="+strKey+"&p="+strPath+"&version="+strVersion; | |
| } | |
| URL iburl = new URL("https://<server address>/evs/downloadFile"); | |
| URLConnection uc = iburl.openConnection(); | |
| uc.setDoOutput(true); | |
| uc.setDoInput(true); | |
| DataOutputStream dout = new DataOutputStream (uc.getOutputStream ()); | |
| dout.writeBytes(params); | |
| dout.flush(); | |
| dout.close(); | |
| //After sending data check for the status of response | |
| String strStatus=uc.getHeaderField("RESTORE_STATUS"); | |
| System.out.println("strStatus:"+strStatus); | |
| //If error then read the message and display the error | |
| if(strStatus!=null && strStatus.equalsIgnoreCase("error")) | |
| { | |
| BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream())); | |
| while ((str = in.readLine()) != null) { | |
| result += str; | |
| } | |
| <%} | |
| //Else download the file | |
| else{ | |
| ServletContext context = getServletConfig().getServletContext(); | |
| String mimetype = context.getMimeType( fileName ); | |
| System.out.println("mimetype::::"+mimetype); | |
| response.setContentType( (mimetype != null) ? mimetype : "application/octet-stream" ); | |
| //response.setContentLength( (int)f.length() ); | |
| response.setHeader( "Content-Disposition", "attachment; filename=\"" + fileName + "\"" ); | |
| BufferedInputStream bis= new BufferedInputStream(uc.getInputStream()); | |
| ServletOutputStream outs = response.getOutputStream(); | |
| byte[] buffer = new byte[30 * 1024]; | |
| int bytesRead = 0; | |
| while ((bytesRead = bis.read(buffer)) >= 0) | |
| { | |
| outs.write(buffer, 0, bytesRead); | |
| } | |
| outs.flush(); | |
| outs.close(); | |
| bis.close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment