Query Attachments (Feature Service/Layer)

URL:
https://<root>/<serviceName>/FeatureServer/<layerId>/queryAttachments
Methods:
GET
Version Introduced:
10.5

Description

The queryAttachments operation is performed on a feature service layer resource. The result of this operation are attachments grouped by the source feature object Ids and global ids (if exist).

Queries must include one of the following parameters: objectIds , globalIds , or definitionExpression . All other parameters are optional and are used to further refine the returned results.

You can provide arguments to the Query Attachments operation as query parameters defined in the following parameters table:

New at 10.9.1

This operation supports a returnCountOnly parameter for hosted feature services that returns the count of attachments per feature. The returnCountOnly parameter is supported when the supportsQueryAttachmentsCountOnly property is set to true (found under advancedQueryCapabilities ).

New at 10.8.1

  • Field names are now returned in addition to the field properties in the queryAttachments operation response. If the field name and property name match, including case, only one value is returned in the response to represent both field and property. As a best practice, it is best to go by the fieldname rather than the property when consuming this in an application.
  • When using the attachmentsDefinitionExpression parameter, you can use the fieldName property from the layer's attachmentProperties object. This describes the names of the fields that can be used in the expression. The layer's attachmentFields object lists more information about these fields, including type, which can be useful when building queries. This information is not provided in the layer resource at earlier releases, but the same field names can be used in those as well.

Request parameters

ParameterDetails

objectIds

(Required)

The object IDs of this layer/table to be queried. This parameter is not designed to be used in conjunction with the globalIds parameter. If you supply globalIds , any objectIds you supply will be ignored.

Syntax

Use dark colors for code blocksCopy
1
objectIds=<objectId1>,<objectId2>

Example

Use dark colors for code blocksCopy
1
objectIds=2

globalIds

(Required)

The global IDs of this layer/table to be queried. This parameter is required if neither objectIds or definitionExpression have been defined.

Syntax

Use dark colors for code blocksCopy
1
globalIds=<globalIds1>,<globalIds2>

Example

Use dark colors for code blocksCopy
1
globalIds=6s430c5a-kb75-4d52-a0db-b30bg060f0b9,35f0d027-8fc0-4905-a2f6-373c9600d017

definitionExpression

(Required)

The definition expression to be applied to the layer. Only those records that conform to this expression will be returned. This parameter is required if neither objectIds or globalIds have been defined.

Example

Use dark colors for code blocksCopy
1
definitionExpression=STATE_NAME = 'Alaska'

attachmentsDefinitionExpression

The definition expression to be applied to the attachments table. Only those records that conform to this expression will be returned. You can get the attachments table field names to use in the expression by checking the layer's attachmentProperties object.

Examples

Use dark colors for code blocksCopy
1
2
3
4
5
//Returns any attachment named 'alaska.geodatabase'
definitionExpression=ATT_NAME = 'alaska.geodatabase'

//Returns any attachment that includes SingleStory in the keyword value. For example, results may include attachments with keyword values "SingleStory,Restaurant" or "SingleStory,Residence" etc.
definitionExpression=keywords like ‘%SingleStory%’

attachmentTypes

The attachment types to return. The following attachment types are supported for ArcGIS Online and ArcGIS Enterprise:

Values: 7z | aif | avi | bmp | csv (added to ArcGIS Enterprise at 10.8.1) | doc | docx | dot | ecw | emf | eps | geodatabase | geojson (added to ArcGIS Enterprise at 10.8.1) | gif | gml | gtar | gz | img | j2k | jp2 | jpc | jpe | jpeg | jpf | jpg | json | m4a | mdb | mid | mov | mp2 | mp3 | mp4 (added to ArcGIS Enterprise at 10.8) | mpa | mpe | mpeg | mpg | mpv2 | pdf | png | ppt | pptx | ps | psd | qt | ra | ram | raw | rmi | sid | tar | tgz | tif | tiff | txt | vrml | wav | wma | wmf | wmv | wps | xls | xlsx | xlt | xml | zip

At this time, the following attachment types are supported in ArcGIS Online only:

Values: gpkg | pbf | sd

Example

Use dark colors for code blocksCopy
1
attachmentTypes=image/jpeg, image/tiff

size

The file size of the attachment is specified in bytes. You can enter a file size range (1000,15000) to query for attachments with the specified range.

Example

Use dark colors for code blocksCopy
1
2
//If definitionExpression=STATE_NAME = 'Alaska', the querying results will return all attachments within the specified file size range (1000-15000)
size=1000,15000

resultOffset

This parameter is designed to be used in conjunction with resultRecordCount to page through a long list of attachments, one queryAttachments request at a time. This option fetches query results by skipping a specified number of records. The query results start from the next record (i.e., resultOffset + 1). The default value is 0. This parameter only applies when supportPagination is true . You can use this option to fetch records that are beyond maxRecordCount .

Example resultOffset setting

Use dark colors for code blocksCopy
1
resultOffset=1000

resultRecordCount

This option fetches query results up to the resultRecordCount specified. When resultOffset is specified and this parameter is not, the feature service defaults to the maxRecordCount The maximum value for this parameter is the value of the layer's maxRecordCount property. This parameter only applies if supportPagination is true .

Example

Use dark colors for code blocksCopy
1
2
//Fetch up to 10 records
resultRecordCount=10

returnUrl

Specifies whether to return the attachment URL. The default is false . This parameter is supported if the supportsQueryAttachmentsWithReturnUrl property is true on the layer. Applications can use this URL to download the attachment image.

Values: true | false

returnMetadata

If true , metadata stored in the exifInfo column will be returned for attachments that have exifInfo . This option is supported only when "name": "exifInfo" in the layer's attachmentProperties includes "isEnabled": true . When set to false , or not set, null is returned for exifInfo .

Values: true | false

keywords

Returns attachments that match the keywords provided. The value provided for this parameter must be an exact match to the attachment's keyword value. This parameter can be set when the layer's attachmentProperties include "name": "keywords" with "isEnabled": true . To query for partial matches, you can use the attachmentsDefinitionExpression parameter instead. See attachmentsDefinitionExpression for examples.

Example

Use dark colors for code blocksCopy
1
keywords = 'motorcycle'

returnCountOnly

New at 10.9.1. Specifies whether to return just the count of attachments per feature or row. Only returns results for features matching the query criteria that have a non-zero number of attachments. The default value is false . This parameter is supported when supportsQueryAttachmentsCountOnly layer property is true (found under advancedQueryCapabilities ).

Values: true | false

f

The response format. The default response format is html .

Values: html | json | pjson

Example usage

Example one

The example below demonstrates how to query attachments using the parent objectsIds . The query results will return only the specified object ids.

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2,4&globalIds=&definitionExpression=&attachmentTypes=&resultOffset=&resultRecordCount=&f=pjson

Example two

The example below demonstrates how to query attachments using the parent globalIds . The query results will returns only the specified global ids.

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=&globalIds=60e35c5a-6bc5-4d52-a6db-b39bf566f7b9,e1f9d927-8fc9-4995-a2f6-373c9600d017&definitionExpression=&attachmentTypes=&size=&resultOffset=&resultRecordCount=&f=pjson

Example three

The example below demonstrates how to query attachments using the definitionExpression as objectid>2 and attachmentTypes as impage /jpeg. The query results will return all image/jpeg attachment types where the object id is greater than 2.

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=&globalIds=&definitionExpression=objectid>2&attachmentTypes=image/jpeg&size=&resultOffset=&resultRecordCount=&f=html

Example four

The example below demonstrates how to query attachments using the definitionExpression STATE_NAME as 'alaska' , resultOffset as 5, and resultRecordCount as 10. The query results will skip the first 5 records and return the next 10 attachments in Alaska.

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2&globalIds=&definitionExpression=STATE_NAME = 'alaska'&attachmentTypes=&size=&resultOffset=5&resultRecordCount=10&f=html

Example five

The example below demonstrates how to query attachments using the attachmentsDefinitionExpression ATT_NAME as 'alaska_geodatabase' and size as 900,7000 . The query results will return all attachments within the specified file size range with the attachment name 'alaska.geodatabase' .

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2&globalIds=&definitionExpression=ATT_NAME = 'alaska.geodatabase'&attachmentTypes=&size=900,7000&resultOffset=&resultRecordCount=&f=html

Example six

The example below demonstrates how to query attachments using the definitionExpression STATE_NAME as 'alaska' , size as 900,7000 , and returnUrl as true . The query results will return all attachments, including URLs, within the specified file size range in Alaska.

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2&globalIds=&definitionExpression=STATE_NAME = 'alaska'&attachmentTypes=&size=900,7000&resultOffset=&resultRecordCount=&returnUrl=true&f=html

Example seven

The example below demonstrates how to query attachments using the definitionExpression as 1=1 and keywords as 'motorcycle'. The query results will return all attachment types that have a keywords value of motorcycle.

Use dark colors for code blocksCopy
1
https://machine.domain.com/webadaptor/rest/services/Hosted/volcano_roop/FeatureServer/0/queryAttachments?definitionExpression=1%3D1&keywords=motorcycle&f=json

JSON Response syntax

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
  "fields": [
    {
      "name": "OBJECTID",
      "type": "<esriFieldTypeInteger>",
      "alias": "<OBJECTID>",
      "sqlType": "<sqlTypeOther>",
      "domain": null,
      "defaultValue": null
    },
    {
      "name": "<GlobalID>",
      "type": "<esriFieldTypeGlobalID>",
      "alias": "<GlobalID>",
      "sqlType": "<sqlTypeOther>",
      "length": 38,
      "domain": null,
      "defaultValue": null
    }
  ],
  "attachmentGroups": [
    {
      "parentObjectId": "<OBJECTID>",
      "parentGlobalId": "<esriFieldTypeGlobalID>",
      "attachmentInfos": [
        {
          "id": "<OBJECTID>",
          "globalId": "<esriFieldTypeGlobalID>",
          "name": "<name>",
          "contentType": "<attachmentTypes>",
          "size": "<size>",
          "url": "<returnUrl>"
        }
      ]
    }
  ]
}

JSON Response example

Example one

The example below demonstrates a response that is returned when the layer's attachmentProperties contains fieldName properties.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
	 "fields": [
    {
			   "name": "objectid_1",
			   "type": "esriFieldTypeOID",
			   "alias": "OBJECTID_1",
			   "domain": null,
			   "defaultValue": null
		  },
		  {
			   "name": "globalid",
			   "type": "esriFieldTypeGlobalID",
			   "alias": "globalid",
			   "domain": null,
			   "defaultValue": null
		  }
	 ],
	 "attachmentGroups": [
    {
		    "parentObjectId": 2,
		    "parentGlobalId": "{F62F4A99-FACB-459D-8E29-7A1044EE2065}",
		    "attachmentInfos": [
        {
			       "id": 1204,
			       "attachmentid": 1204,
			       "globalId": "{058333D1-D96C-4C19-A787-553FF119FD53}",
			       "globalid": "{058333D1-D96C-4C19-A787-553FF119FD53}",
			       "name": "red.png",
			       "att_name": "red.png",
			       "contentType": "image/png",
			       "content_type": "image/png",
			       "size": 381,
			       "data_size": 381
		      }
      ]
	   }
  ]
}

Example two

The example below demonstrates a queryAttachments response when returnCountOnly is true . In the response below, the feature with parentObjectId=25 that has two attachments, while the feature with parentObjectId=21 has five attachments.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
  "fields": [
    {
      "name": "OBJECTID_1",
      "type": "esriFieldTypeOID",
      "alias": "OBJECTID_1",
      "sqlType": "sqlTypeOther",
      "domain": null,
      "defaultValue": null
    },
    {
      "name": "GLOBALID",
      "type": "esriFieldTypeGlobalID",
      "alias": "GLOBALID",
      "sqlType": "sqlTypeOther",
      "length": 38,
      "domain": null,
      "defaultValue": null
    }
  ],
  "attachmentGroups": [
    {
      "parentObjectId": 25,
      "parentGlobalId": "477711fe-461d-4fde-9aab-17cf3d38ad4f",
      "count": 2
    },
    {
      "parentObjectId": 21,
      "parentGlobalId": "6066fb7d-e7b1-44de-9465-63a3df05bb59",
      "count": 5
    }
  ]
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.