Add Attachment

URL:
https://<root>/<serviceName>/FeatureServer/<layerId>/<featureId>/addAttachment
Methods:
POST
Required Capability:
Create or Update
Version Introduced:
10.0

Description

This operation adds an attachment to the associated feature (POST only). Adding an attachment is a feature update, but is support with either the Update or the Create capability. The addAttachment operation is performed on a feature service feature resource.

Since this request uploads a file, it must be a multipart request pursuant to IETF RFC1867.

This operation is available only if the layer has advertised that it has attachments. A layer has attachments if its hasAttachments property is true .

See the Limiting upload file size and file types section under Uploads to learn more about default file size and file type limitations imposed on attachments.

The request to upload an item file must be a multipart request pursuant to IETF RFC1867. See the Add Item page for more information.

The result of this operation is an array of edit result objects. Each edit result indicates whether or not the edit was successful. If successful, the objectId of the result is the ID of the new attachment. If unsuccessful, it also includes an error code and error description.

You can provide arguments to the addAttachment operation as defined in the following parameters table:

Request parameters

ParameterDetails

attachment

The file to be uploaded as a new feature attachment.

The content type, size, and name of the attachment will be derived from the uploaded file.

gdbVersion

The geodatabase version to apply the edits. This parameter applies only if the isDataVersioned property of the layer is true .

If the gdbVersion parameter is not specified, edits are made to the published map’s version.

Syntax: gdbVersion=<version>

Example: gdbVersion=SDE.DEFAULT

returnEditMoment

This option was added at 10.5 and works with ArcGIS Server services only.

Optional parameter specifying whether the response will report the time attachments were added. If returnEditMoment = true , the server will return the time in the response's editMoment key. The default value is false .

Values:true|false

Example: returnEditMoment=true

uploadId

Added to the July 2014 of ArcGIS Online and ArcGIS 10.4 Server.

The ID of the attachment that has been uploaded to the server. This parameter only applies if the supportsAttachmentsByUploadId property of the layer is true .

keywords

Sets a text value that is stored as the keywords value for the attachment. This parameter can be set when the layer has an attachmentProperties property that includes "name": "keywords" with "isEnabled": true . If the attachments have keywords enabled and the layer also includes the attachmentFields property, you can use it to understand properties like keywords field length.

Example

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

f

The response format. The default response format is html .

Values: html | json

Example usage

Add an attachment using the addAttachment operation on a feature service feature resource. In this sample URL, the addAttachment operation is performed on feature ID 818654 belonging to layer 0 of the 311Incidents feature service:

Use dark colors for code blocksCopy
1
https://services.myserver.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/818654/addAttachment

The input parameter attachment to this operation is a file.

JSON Response syntax

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
{
  "addAttachmentResult": {
    "objectId": <attachmentId>,
    "globalId": <globalId>,
    "success": <true | false>,
    "error": { //only if success is false
      "code": <code1>,
      "description": "<description>",
    }
  }
}

JSON Response example

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
{
  "addAttachmentResult": {
    "objectId": 58,
    "globalId": null,
    "success": true
  }
}

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