Show attachment URLs in queries and when data exporting

:book: This guide walks through how to configure Specify so that you can export Collection Object Attachment URLs from your Specify Attachment/Asset Server that can link to your images when sharing data internally or with data aggregators. These instructions can be adapted to work with any table’s attachments.

[!warning]
You must have the Specify Asset Server configured and publically accessible. To see if this is the case, try to view several Specify attachments in your web browser.


  1. In App Resources, go to the DataObjFormatters resource present in the collection or discipline you are configuring this for. This is most likely under your discipline. See an example.

In the format section, add the following XML snippet:

    <format
        name="CollectionObjectAttachment"
        title="CollectionObjectAttachment"
        class="edu.ku.brc.specify.datamodel.CollectionObjectAttachment"
        default="true"
        >
        <switch single="true">
            <fields>
                <field sep="http://biimages.biodiversity.ku.edu/static/Ichthyology/originals/">attachment.attachmentLocation</field>
            </fields>
        </switch>
    </format>
  1. Replace http://biimages.biodiversity.ku.edu/static/Ichthyology/originals/ in the above XML snippet with the base URL for your attachments.

[!example] For example, here is another URL for an attachment:

https://demo-assets.specifycloud.org/fileget?coll=sp7demofish&type=O&filename=sp62280762705929643056.att.JPG&downloadname=DDB13-16b.JPG

I can safely remove everything following the filename= as that is where the AttachmentLocation information is located.

I would replace

http://biimages.biodiversity.ku.edu/static/Ichthyology/originals/

with

https://demo-assets.specifycloud.org/fileget?coll=sp7demofish&amp;type=O&amp;filename=`

:warning: Replace ampersands (&) with its XML equivalent, &amp;.


As you may have known, the AttachmentLocation field contains the actual name given to the attachment by Specify when it is added to the asset server:

By establishing this format, we are making it so that this is added to the end of the attachment base URL so that the images can be linked to from external sources (GBIF, iDigBio, etc.).

  1. In the aggregator section, add the following XML snippet:
    <aggregator name="CollectionObjectAttachment"
                title="CollectionObjectAttachment"
                class="edu.ku.brc.specify.datamodel.CollectionObjectAttachment"
                default="true"
                separator=" | "
                ending=""
                count="0"
                format="CollectionObjectAttachment"
                orderfieldname="ordinal"
               />
  1. In the Schema Config tool, navigate to the CollectionObjectAttachment table:

    ex. https://sp7demofish.specifycloud.org/specify/schema-config/en/CollectionObjectAttachment/

    Once there, choose both the CollectionObjectAttachment aggregation and format.

  2. Click Save in the top right of the schema config window, clear your cache, then run a query! You should now see the format and aggregation in action!

1 Like