### Introduction

In this blog we will show you how to use the FME HTTPCaller to add an attachment to an existing feature in ArcGIS Online. We will use the ArcGIS REST API addAttachment operation to POST our file to a feature service feature resource. A feature resource represents a single feature in a layer in an ArcGIS Online feature service.

Since this operation uploads a file, it must send a multipart request pursuant to IETF RFC1867. In this example we will upload PDF files, but this protocol does support other MIME types as well.

### Preparation

• Enable Attachments: to be able to attach a file to a feature, the layer must support attachments, i.e. its hasAttachments property should be TRUE. If this property is set to FALSE you will get an error 400:Layer does not support attachments.
• Generate Token: your FME workspace should contain a separate HTTPCaller using the generateToken operation to obtain an access token. If you do not provide a (valid) token you will get an error 499:Token Required or 498:Invalid token.
• Obtain OBJECTID of those features that will get an attachment: to attach a file to a feature using the ArcGIS REST API you will need to provide the OBJECTID of this feature (see sample URL below). To obtain this OBJECTID you will have to query the feature layer. You should add a separate HTTPCaller to your FME workspace using the query operation to accomplish this.
• Obtain name of and path to the file to upload: use a PATH Reader in your FME workspace to obtain the details of the attachment you want to upload.

### Sample URL

In this sample URL, the addAttachment operation is performed on the feature with the OBJECTID @Value(OBJECTID) belonging to layer 0 of the Points feature service:

https://services.myserver.com/arcgis/rest/services/Points/FeatureServer/0/@Value(OBJECTID)/addAttachment

### HTTPCaller Parameters

After you have taken the preparatory steps above, you should be able to configure the HTTPCaller with the following parameters (click on the images for detailed information):

Name Value Request URL A valid URL pointing to your layer plus /@Value(OBJECTID)/addAttachment HTTP Method POST Query String Parameters token token (Attribute Value) f json Upload Data Multipart / Form Data Multipart Upload name String Upload attachemnet filename String Upload path_filename (Attribute Value) fileobj File Upload path_windows (Attribute Value) content_type String Upload application/pdf

### JSON response example

Your FME workspace will most probably not have a Writer (if adding the attachments was the final purpose of your script). But you can always connect an Inspector to view the results in FME Data Inspector. The content of the column _response_body should look something like this:

{ "addAttachmentResult" : { "objectId" : 31, "globalId" : "1e4c5679-b952-4f40-9eec-6134131f84a0", "success" : true } }

Happy coding!

Egge-Jan Pollé