Re: View Attachement from Dataverse in Form / Page
@MiniDev- This is how I was finally able to do it...
You're correct that files are uploaded/stored in the Note (annotations) table when you use the File Attachments control on a form. Using FetchXml, you can link to the annotations table in order to get/show the required fields necessary. You're going to need the related mimetype and documentbody fields at a minimum, and will likely need the filename field too. It would look something like this:
{% fetchxml files %}
<fetch mapping='logical'>
<entity name="your_tables_logical_name">
<attribute name="a_column_from_the_parent_table" />
<attribute name="another_column_from_the_parent_table" />
<link-entity name="annotation" from="objectid" to="your_tables_logical_nameid" link-type="outer" alias="your_alias">
<attribute name="filename" />
<attribute name="mimetype" />
<attribute name="documentbody" />
</link-entity>
</entity>
</fetch>
{% endfetchxml %}
I assume you know where to get the logical names for the table and columns If not, you can go to Data in the Design Studio and look at the associate Table Properties and Column Properties.
Once you've fetched the data with the linked notes items, you can iterate through them and use the Base64 encoding of the documentbody with the mimetype to either display the image or download the document. It would look something like this:
<div class="row">
{% if files.results.entities.size > 0 %}
{% for file in files.results.entities %}
<div class="col-lg-6">
<p>{{ file.a_column_name_from_the_parent }}</p>
<img src="data:{{ file['your_alias.mimetype'] }};base64,{{ bio['your_alias.documentbody'] }}" />
<a href="data:{{ file['your_alias.mimetype'] }};base64,{{ bio['your_alias.documentbody'] }}" download={{ file['your_alias.filename'] }}> Download Link </a>
</div>
{% endfor %}
{% endif %}
</div>
Notes:
- The <img> tag will display the image on screen
- The <a> tag with the 'download' attribute will allow the user to download the file by clicking on the link and will assign the stored document filename as the default filename.
- your_alias can be anything you want, but it is required for the linked entities to function properly.
- This should work for any images and document types, but you may need to adjust it accordingly for any other file types.