Image and other attachment expressions

Examples of report expressions for image and attachment questions are provided below.

For image questions, sizes can be set to ensure that your reports have images of consistent size. The format for these expressions is as follows:

${image1 | size:width:height:max_width:max_height}

The width and height values control the set size of the image, measured in pixels. While these values are required for the expression, providing a value of 0 places no restriction on that dimension of the image. For example, the following expression makes the width of an image 300 pixels while preserving the aspect ratio of the image:

${image1 | size:300:0}

The maximum height and width values limit the maximum size of an image and are optional values. The following example makes the width of an image 300 pixels and restricts the image height to no more than 200 pixels:

${image1 | size:300:0:0:200}

The example below uses the rotate method to define the clockwise rotation of the image. It accepts values from 0 to 360.

${image1 | size:300:0:0:200 | rotate:90}

Image questions can also have image details extracted and displayed in a survey response. This can be used to display the file name and size of the image as follows:

${image1 | getValue:"name"}

${image1 | getValue:"size"}

${image1 | getValue:"width"}

${image1 | getValue:"height"}

The same method can be used to display EXIF data from the image, showing details of where and when a photo was taken, as follows:

${image1 | getValue:"x"}

${image1 | getValue:"y"}

${image1 | getValue:"date"}

${image1 | getValue:"time"}

${image1 | getValue:"direction"}

To display the original image at its full size and quality, use the expression without any method, or use the getValue expression without any value, as follows:

${image1} or ${image1 | getValue:""}

The following example displays the original image at full quality but at a set size, using the getValue and size expressions together:

${image1 | getValue:"" | size:300:0}

Note:

If you are setting an image's size while using any other expression parameter, size must be placed last in the expression.

Dates and times are stored as strings in EXIF data, so these values cannot be formatted in a report using the format expression for date and time questions. If formatting these values is important, you can perform the EXIF extraction as part of the survey using the pulldata("@exif") function. For more information, see Images.

The getValue expressions above can also be used to extract data from any valid properties in any type of attachment, including the results of image, audio, and file questions. The properties that can be extracted from all attachments are as follows:

${file1 | getValue:"name"}

${file1 | getValue:"size"}

${file1 | getValue:"globalId"}

${file1 | getValue:"id"}

${file1 | getValue:"contentType"}

${file1 | getValue:"keywords"}

To display an online image, provide its source URL with the src expression when referring to the $image keyword instead of a question name:

${$image |
src:"https://upload.wikimedia.org/wikipedia/commons/1/13/Esri_Headquarters%2C_Building_Q.jpg"
| size:400:0}

To return multiple images submitted to the same question in a response, use the following placeholders with each placed on a dedicated line:

${#image1}
${$file}
${/}

The $attachment keyword can be used to iterate all attachments of the current feature:

${#attachment}
${$file}
${/}

This method is useful for displaying images in ArcGIS Enterprise versions earlier than 10.8.1, or for displaying images that were added to a feature outside of Survey123 in which attachments do not have a value for the keywords property. The following example displays the file names of all attachments in a feature:

${#$attachment}
${$file|getValue:"name"}
${/}

To display specific attachments, include the attachmentsDefExp method to identify the attachment:

${#image1 | attachmentsDefExp:"DATA_SIZE > "+1*1024*1024}...${$file}...${/}

${#$attachment | attachmentsDefExp:"Keywords = 'image1'"}...${$file}...${/}

${#$attachment | attachmentsDefExp:"CONTENT_TYPE like '%image%'"}...${$file}...${/}

Note:
The attachmentsDefExp method behaves the same as the Query attachments attachmentsDefinitionExpression property. Review the attachmentProperties object in the layer's JSON to see which fields can be used in the attachment query.