I'm trying to figure out if there's a way that I can leverage Salesforce Files, plus the Content Delivery and Public Links feature to create sort of a poor man's CDN for serving up images to a Salesforce Site. Right now, I can do the following things manually (in Lightning Experience):
- Upload an image file to my asset library.
- Right-click on the file and select "Public Link" and then click "Create Link".
- Navigate to this public link in the browser; it launches a preview page, where I can see a preview of the image.
- Right-click on the preview of the image in the browser and select "Copy image location".
- Paste this image location into the "src" attribute of an "img" tag on my Site page.
I'm basically wondering if there's a way I can programmatically do steps 2, 3 and 4 to get the URL for the image in a more direct way. I can see that creating the public link creates a ContentDistribution record in the database, which has a field (DistributionPublicUrl) that looks something like this:
This is the link that loads the preview page. The actual image location looks something like this:
Is there a way to create the public link for a file via Apex or some other mechanism?
Once I get the public link, is there a blessed way to derive the "src" URL for the image?