Linking Data Records to Image Files

This topic explains how to link data grids to image files which reside either on the same LabKey Server, or somewhere else on the web.

This feature can be used with any LabKey data table as an alternative to using either the File or Attachment field types.

For assay designs, see the following topic: Linking Assays with Images and Other Files.


Suppose you have a dataset where each of row of data refers to some image or file. For example, you have a dataset called Biopsies, where you want each row of data to link to an image depicting a tissue section. Images will open in a new tab or download, depending on your browser settings.

Below is an example Biopsies table:



How do you make this dataset link to the slide images, such that clicking on slide1.jpg shows the actual image file?


To achieve this linking behavior, follow these steps:

  • Upload the target images to the File Repository.
  • Create a target dataset where one column contains the image names.
  • Build a URL that links from the image names to the image files.
  • Use this URL in the dataset.
Detailed explanations are provided below:

Upload Images to the File Repository

  • Navigate to your study folder.
  • Go to (Admin) > Go To Module > File Content.
  • Drag-and-drop your files into the File Repository. You can upload the images directly into the root directory, or you can upload the images inside a subfolder. For example, the screenshot below, shows a folder called images, which contains all of the slide JPEGs.
  • Acquire the URL to your image folder: In the File Repository, open the folder where your images reside, and scroll down to the WebDav URL.
  • Open a text editor, and paste in the URL, for example:

Create a Target Dataset

Your dataset should include a column which holds the file names of your target images. See "Biopsies" above for an example.

For details on importing a study dataset, see Import Datasets.

To edit an existing dataset to add a new column, follow the steps in this topic: Dataset Properties.

Build the URL

To build the URL to the images, do the following:

  • In your dataset, determine which column holds the image names. In our example the column is "TissueSlide".
  • In a text editor, type out this column name as a "substitution token", by placing it in curly brackets preceded by a dollar sign, as follows:
  • Append this substitution token to the end of the WebDav URL in your text editor, for example:${TissueSlide}

You now have a URL that can link to any of the images in the File Repository.

Use the URL

  • Go the Dataset grid view and click Manage.
  • Click Edit Definition.
  • Click the Fields section.
  • Expand the field which holds the image names, in this example, "TissueSlide".
  • Into the URL field, paste the full URL you just created, including the substitution token.
  • Click Save.
  • Click View Data.
  • Notice that the filenames in the TissueSlide field are now links. Click a link to see the corresponding image file. It will open in a new tab or download, depending on your browser.

If you prefer that the link results in a file download, add the following to the end of the URL in the dataset definition.


Resulting in this total URL on the Display tab for the TissueSlide field.${TissueSlide}?contentDisposition=attachment

If you prefer that the link results in viewing the file in the browser, add the following:


Related Topics

Was this content helpful?

Log in or register an account to provide feedback

expand allcollapse all