Embed Database Images in a Report

This guide assumes basic knowledge of the Schema Configurator and Specify iReport/Jaspersoft Studio.

These instructions are based on a Collection Object query. You will need to slightly alter the configuration if you want to use another base table.

Only JPG, JPEG, PNG, and GIF filetypes are supported. If you have PDFs or other filetype attachments, make sure to add the optional step of a checkbox on your forms. The report runner will give an error if an unsupported filetype is used.

Step 1: Configure your schema to show two important fields:

Make sure that in the Schema Configuration under the collectionobjectattachment table that the fields attachment and ordinal are unhidden.

Under the attachment table, make sure that attachmentLocation is not hidden.

Step 2: Now you must configure a query for your label or report.


Optionally, you can add a Yes or No checkbox to your Collection Object form to decide if an image should appear. This can prevent the report from having an error due to a dead image link or unsupported filetype. It could look something like this:

Here’s an example query:


This query is for demonstration purposes, your query can be as precise as you wish.

This query needs to include these two elements:

  • Collection Object → Collection Object Attachment → Ordinal = 0
    This ensures that the first image is selected and prevents duplicate labels for the same collection object record.

  • Collection Object → Collection Object Attachment → Attachment Location
    This is the actual name of the attachment in the database

Step 3: Create a report or label using this query

Using iReport, create a label or report for your query. The following fields should be visible after it is created:

image

Drag and drop every field you would like visible except for the $F{Attachment_Location}.

Step 4: Navigate to an image in your database. You can choose any image from the Attachments page in the navigation bar or navigate directly to the image in your web browser.

Double-click on the image.

Copy the entire URL from your browser window.

For Specify Cloud instances, your URL will look something like this:

https://demo-assets.specifycloud.org/fileget?coll=sp7demofish&type=O&filename=sp65838284700706862256.att.JPG&downloadname=C%3A%5CUsers%5Cabentley%5CDesktop%5CLarge+pictures_For+Andy%5C40276.JPG&token=

You will need to remove everything after filename=.

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

This is the first piece of the expression you will use in iReport/Jaspersoft Studio.

Step 5: Add an image to the report.

Select the image icon from iReport’s toolbar and drag your image bounds onto the report.

image

Right-click on your image and click Properties.

image

Navigate to the Image tab and now you can modify your image expression.

image

Put the base URL found in the previous step in double quotes "https://demo-assets.specifycloud.org/fileget?coll=sp7demofish&type=O&filename=", then a +, then $F{Attachment_Location}. This completed expression will now pull your image when the report runs.

This expression says that if there is no Attachment Location, nothing will display. If there is, the filename of the image will be added to the end of the attachments base URL we found in the previous step.

Example Image Expression:

($F{Attachment_Location}==null?"":"https://demo-assets.specifycloud.org/fileget?coll=sp7demofish&type=O&filename="+$F{Attachment_Location})

Step 6: Save and run the report.

If everything was done correctly, it should run and display without any issue! This is compatible with both Specify 6 and 7.

Please let us know if you need any help!