• RajKuch
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi,

  I am researching on how download or move a pdf file from salesforce.com  .. I have the URL and can access the URL and open the file ..but don't know which Java API in saleforce provides for java development to get move this file from saleforce to another server.  I would appreciate any response.  I saw some replies by Simon on similar downloading files but I am not able to use it.

 

I would appreciate a code sample

 

thanks

raj

im trying to download a specific document that is selected by a user. im using the code below, the url being sent is https://na7.salesforce.com/servlet/servlet.FileDownload?file=D015A0000005QphPIAS. the issue im facing is that the saved file always contains the body of the salesforce login page (the returned file code is below).

 

HttpClient httpclient = new HttpClient();
                GetMethod get = new GetMethod(salesForceFacade.getSfSession().getInstanceUrl() + "/servlet/servlet.FileDownload?file="+salesforceDocument.getId());

                // set the token in the header
                get.setRequestHeader("Authorization", "OAuth " + salesForceFacade.getSfSession().getAccessToken());
                httpclient.executeMethod(get);
                System.out.println(get.getURI());
                System.out.println(get.getDoAuthentication());
                System.out.println(get.getResponseBodyAsString());
               
               // URL url = new URL(salesForceFacade.getSfSession().getInstanceUrl()+"/servlet/servlet.FileDownload?file%3D"+salesforceDocument.getId());
                    InputStream is = get.getResponseBodyAsStream();
                    OutputStream os = new FileOutputStream("C:\\Users\\user\\Desktop\\"+salesforceDocument.getName()+"."+salesforceDocument.getType());

                    byte[] b = new byte[1024];
                    int length;

                    while ((length = is.read(b)) != -1) {
                            os.write(b, 0, length);
                    }

                    is.close();
                    os.close();

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">





<script>
var escapedHash = '';
var url = 'https://login.salesforce.com/?ec=302&startURL=%2Fservlet%2Fservlet.FileDownload%3Ffile%3D015A0000001QphPIAS';
if (window.location.hash) {
   escapedHash = '%23' + window.location.hash.slice(1);
}
if (window.location.replace){ 
window.location.replace(url + escapedHash);
} else {;
window.location.href = url + escapedHash;
} 
</script>

</head>


</html>



<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->