# Images from Files

In order to add images from a Salesforce File, a Public URL must be created in order to download/use the File as an image in a generated document.

This can be accomplished manually, by pulling up the File record and [clicking “Public Link”](https://help.salesforce.com/s/articleView?id=sf.collab_files_sharing_via_link.htm\&type=5). Once this is done, right-clicking on the opened image and copying the link should provide a link that can be successfully pulled into a document during generation.

For clients who want to automate creating public links and using them in generated documents on the regular, this can be accomplished with Apex, directly inserting the File (ContentVersion) into the public link table (ContentDistribution) like so:

{% code title="Apex" %}

```apex
/* Getting ContentVersion file using ContentDocument Id */
ContentVersion file = [SELECT Id, Title FROM ContentVersion WHERE ContentDocumentId = '<Content Document ID>'].Id;

/* Creating ContentDistribution record */
insert new ContentDistribution(
   Name = file.Title,
   ContentVersionId = file.Id,
   PreferencesAllowViewInBrowser= true
);
```

{% endcode %}

Or perhaps a triggered Flow is preferable:

{% hint style="info" %}
Be sure to:

* Make sure public link base URLs are included in Remote Site Settings
* Note that a “download URL” will effectively download an image for document generation
  {% endhint %}

Source: <https://forcepanda.wordpress.com/2021/05/04/generating-public-url-for-salesforce-files/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/template-architecture/images-in-s-docs/dynamic-image-solutions/images-from-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
