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
KJ1122KJ1122 

How to see attachment content/download file via REST API

Hi All,
I was able to succesfully get the access token and make calls to see my 2 records which i had attached.
Using the below calls for my instance i am able to see the attributes, contentDocumentLink, id, LinkedEntityID and ContentDocumentID, VersionData as well.

What steps should i do next to make call to see my document content/download my file?

Postman Call:
/services/data/v43.0/query?q=select id, LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId = '0016asdasd33'

Postman call to get version data:
/services/data/v43.0/query?q=SELECT VersionData FROM ContentVersion WHERE (ContentDocumentId = '069sdsds' or ContentDocumentId = '069asdssd') AND IsLatest = true

 
Best Answer chosen by KJ1122
David Zhu 🔥David Zhu 🔥
ConventVersion cn = [SELECT VersionData FROM ContentVersion WHERE (ContentDocumentId = '069sdsds' or ContentDocumentId = '069asdssd') AND IsLatest = true];

string x = EncodingUtil.base64Decode(EncodingUtil.base64Encode(cn.VersionData)).toString();

You may use the above code snippet to get the actual file data.

All Answers

David Zhu 🔥David Zhu 🔥
VersionData in ContentVersion contains blob file data. Your last call has already made it.
 
David Zhu 🔥David Zhu 🔥
ConventVersion cn = [SELECT VersionData FROM ContentVersion WHERE (ContentDocumentId = '069sdsds' or ContentDocumentId = '069asdssd') AND IsLatest = true];

string x = EncodingUtil.base64Decode(EncodingUtil.base64Encode(cn.VersionData)).toString();

You may use the above code snippet to get the actual file data.
This was selected as the best answer
KJ1122KJ1122
Ok. but that does not seem to return a base64 output. It seems to be returning back a content type of application/octetstream.  Is that what is expected?
services/data/v43.0/sobjects/ContentVersion/0686Casadads/VersionData (response of this call is content type of application/octetstream)

The url i am hitting above is what i got in the response from:
/services/data/v43.0/query?q=SELECT VersionData FROM ContentVersion WHERE (ContentDocumentId = '069sdsds' or ContentDocumentId = '069asdssd') AND IsLatest = true

 
KJ1122KJ1122
Thanks David. I have not writtent the code as yet. Was playing with postman till now. Is there an example for retreiving using Golang?
David Zhu 🔥David Zhu 🔥
I have no experience with Golang and really cannot provide help on this.
Hema kulkarni 30Hema kulkarni 30
Hi KJ1122/David Zhu,

I'm new to POSTMAN . I'm trying same scenario but not able to get the actual file from ContentVersion. Could you please help me with the actual code that needs to sent with POSTMAN Get call?

Thanks in Advance!