+ Start a Discussion
David FekkeDavid Fekke 

sfc/servlet.shepherd/document/download servlet is not returning a document when called

We have an Android app that needs to be able to download documents outside of a WebView. Whenever we call this servlet from the DefaultHttpClient, we are returned the following text instead of the file;
var url = window.location.pathname + window.location.hash;
if(window.location.search && window.location.search.length > 1){
    url += window.location.search; // #189617

I am passing in the cookie from the previous request. I am not sure if this is being caused because of a 302 or there is another piece of data we are not passing in the request.
David FekkeDavid Fekke
I was never able to get this to work. I am assuming that there is something about the request that the servlet does not like, and returns this bogus 200 response.

I was able to download the file using another part of the SalesforceMobileSDK, specifically a RestRequest through the Salesforce Rest API. The solution was to lookup the ContentVersionId by using the ContentDocumentId that is the last parameter on the original servlet path. Here is the SOQL I used to find the ContentVersionId;

SELECT Id, FileType, FileExtension FROM ContentVersion WHERE ContentDocumentId = '" + ContentDocumentId + "'

I then created a RestRequest using the ContentVersion endpoint;

request = new RestRequest(RestRequest.RestMethod.GET, "/services/data/" + versionNumber + "/sobjects/ContentVersion/" + ContentVersionId + "/VersionData", null);

The VersionData field will return the data for the file.

This solution is not ideal because it require the app developer to make two different requests to Salesforce to get the file, but it solved our problem. Idealy Salesforce should make an endpoint that would return the file with one request.