REST Service to Expose Attachments as Public CURL
My use case behind this blog post is to expose Salesforce Attachment (Image/Pdf/Video) as a public accessible CURL, without having to authenticate to Salesforce. And we are going to use REST Web-services and Public Sites to do this!
Step 1: Create an Apex REST class with below code snippet.
Step 2: Create Public Site with below settings and also make sure to enable access for the above class on this specific Site Profile using "Public Access Settings".
Now go ahead and attach few attachments like image/pdf/gif on Account object and have those attachment id's handy for testing. Below I am going to test with those Id's using Workbench/CURL and also from the browser to see the responses!
Results from Workbench Testing:
Results from CURL Testing:
Now when I use above Curl's to open them in any browser, It should let me view the actual Attachment!
Sample Gif in a browser:
Sample Pdf in a browser:
Few Pros and Cons to consider before implement above: