function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JustinMcNally21JustinMcNally21 

Data download URL for Files attached to chatter posts prompt for login? | Chatter Rest API

So the problem im having is when a user on my applicaiton clicks to download a file attached to a chatter post it prompts them to login. is there a way to add the session id or oauth token to the request to allow the file to be served the file to people.

Thomas CookThomas Cook

We are aware of this issue and hope to fix it soon.

pkolyvanispkolyvanis

Hi Thomas,

 

Any updates on this issue?

 

I tried fetching a chatter document from my iOS app using the oAuth accessToken on my request but I was still prompted to login.

 

Many thanks in advance,

Panos.

pkolyvanispkolyvanis

On a seperate note, Chatter for iPhone seems to fetch attachments without any issues.

 

Could somebody from Salesforce, let us know how they did it and if they are using an alternative to the chatter rest api supplementaryProperties.data[0].downloadUrl?

 

Thanks in advance,

Panos. 

Thomas CookThomas Cook

The fix will come in a future release.

pkolyvanispkolyvanis

OK thanks,

 

As a workaround, I am using the REST API for now...

 

i.e. constructing the url:

var fileUrl = instanceURL +'/services/data/v21.0/sobjects/feedItem/'+ fileId +'/ContentData';

and then passing the OAuth token as a request header on my http get request.

remyaMohananremyaMohanan

Hi,

 

I am also trying to use to download attachment funtionality. I want to clarify my doubts here. What is the instanceURL which you are talking about? and how do I pass the  OAuth token?

 

Thanks.

remyaMohananremyaMohanan

Is this issue fixed? As mentioned in the above thread, the fix was supposed to come in the future release. Has it already been rolled out?

Thanks,

Thomas CookThomas Cook

The original issue is fixed, that is, if you use the download URL (with the appropriate instance info prepended) passing the OAuth token in the HTTP GET request's Authorization header (like you'd do for any of the other REST requests) you should get the binary file data back in the response.

Thomas CookThomas Cook

Oops - I got my posts confused. This original issue is that the download link currently requires OAuth authentication, which you can't provide in an <a href='...">download</a> type HTML tag. This problem still exists for people building web UIs. The only work around for this is to tunnel the request through a proxy server that can pass the OAuth credentials to Salesforce, or something like that.

Thomas CookThomas Cook

The SObject workaround listed previously in this discussion is also a possibility.

remyaMohananremyaMohanan

I tried SObject workaround and I got the follwing response :

 

 [{"message":"The requested resource does not exist","errorCode":"NOT_FOUND"}]

 

The url used in the service is:

url="/services/data/v21.0/sobjects/feedItem/"+fileid+"/ContentData"

Rest of the services which I am using are v23.0. Is this the reason for error response?

 

remyaMohananremyaMohanan

Hi developers,

 

Finally I am getting a binary file response using the download url and I am able to get the download window. But the problem here is that even after setting the contentType with mime type I am not getting the file extension and I am getting a .part file. Can we get the extension of the file in the json response?

Below is the service code:

 

objHttpServletResponse.setContentType(mimeType);

//here i have to manually set the file extension according to mime type.

if (mimeType.equals("application/vnd.ms-excel")){
            fileExt="xls";   

}

objHttpServletResponse.setHeader("Content-Disposition","attachment; filename=\""+filename+"."+fileExt+"\"");