1

I want to download the file or ContentDocument using non-chatter REST API. I have explored that we can download any ContentDocument or file by using following kind of chatter REST API (which is actually downloadUrl):

"/services/data/v32.0/chatter/files/06917000000XXXXAAA/content?versionNumber=1"

But I don't want to use chatter API (like above example) to download the file because chatter API has very less quota to call.

So, Is there any other method to download the file except the above mentioned method.

Thanks, Zeeshan

0

The 06917000000XXXXAAA in the URL is the ContentDocument ID, and the versionNumber=1 is the version number of the ContentVersion. You can use a SOQL query to get the binary data:

SELECT VersionData FROM ContentVersion WHERE ContentDocumentId='069...' AND VersionNumber=n
  • Thank you, I tried your soql on workbench like following: /services/data/v32.0/query/?q=SELECT+VersionData+FROM+ContentVersion+WHERE+ContentDocumentId='069170000006t37AAA'+AND+VersionNumber='1' – Zeeshan Zahid Mar 4 '16 at 7:04
  • And got link of VersionData in response: { "totalSize" : 1, "done" : true, "records" : [ { "attributes" : { "type" : "ContentVersion", "url" : "/services/data/v32.0/sobjects/ContentVersion/068170000006qsFAAQ" }, "VersionData" : "/services/data/v32.0/sobjects/ContentVersion/068170000006qsFAAQ/VersionData" } ] } – Zeeshan Zahid Mar 4 '16 at 7:08
  • But when I tried VersionData link then got only this response: "Raw Response 1" – Zeeshan Zahid Mar 4 '16 at 7:09
  • I have read the Documentation about VersionData that it contains base64 encoded data, but I am not getting anything like it – Zeeshan Zahid Mar 4 '16 at 7:11
  • Can you try using curl to test things out, as described in developer.salesforce.com/docs/atlas.en-us.200.0.api_rest.meta/…? The VersionData URL should work. – alouie Mar 4 '16 at 8:05
0

You can download a file by forming the URL

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

Get the contentVersion ID of the file you want to download and form the above url. that URL will download if the file's Extension has Download behavior set up in File Upload and Download Security enter image description here

If it has execute in browser it will preview.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.