Run a REST GET request hitting this url. It should give you the file content. You can try this via WORKBENCH, which downloads your file. If you try the same using REST API call in apex, it should give you the body of the file.
Give a try and see if it works.
Sample Http REST request is below. Replace the Id of the ContentVersion in below code and it returns you the file body.
Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v42.0/sobjects/ContentVersion/06890000003oTkqAAE/VersionData');
req.setMethod('GET'); req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId()); req.setHeader('Content-Type', 'application/json'); HttpResponse res = h.send(req); system.debug(res.getBody());
Can you please check the below Stack exchange question which is similar. You can use the similar SOQL to get it.
https://salesforce.stackexchange.com/questions/215115/how-to-retrieve-the-file-content-for-a-contentdocument-object
If this solution helps, Please mark it as best answer.
Thanks,
By using the below SOQL query you will get the link some thing like below
Run a REST GET request hitting this url. It should give you the file content. You can try this via WORKBENCH, which downloads your file. If you try the same using REST API call in apex, it should give you the body of the file.
Give a try and see if it works.
Sample Http REST request is below. Replace the Id of the ContentVersion in below code and it returns you the file body.
Thanks,
You dont need to perform REST, you can just get VersionData and make it String:
And in body you will see full body of the fileActually, to get the file content without using salesforce web service is the following (file blob must be base64 encoded):