posted on behalf of user: Eric Thomas.
Hello,
Has anyone used the REST API to POST an attachment (photo.png) to a Feature Service using `addAttachment`? The documentation seems incomplete.
In Postman:
- Method: POST
- URL: https://services1.arcgis.com/<serviceName>/ArcGIS/rest/services/<name>/FeatureServer/0/addAttachment?
- POST Params: `token` : `<myToken>, `f` : `json`
- POST Body:
- Tried `form-data` with `key` : `attachment` and `value` : `file` and selected a .png file. DID NOT WORK
- Tried `binary` and selected a .png file. DID NOT WORK
- Response:
{
"error": {
"code": 400,
"message": "Error: Feature (ID: addAttachment) not found",
"details": [
"Unable to retrieve feature."
]
}
}
The documentation states that "...This operation is available only if the layer has advertised that it has attachments. A layer has attachments if its hasAttachments property is true."
My feature service seems to have hasAttachments set to true...
...but the error is shown when I put this url into the browser:https://services1.arcgis.com/<serviceName>/ArcGIS/rest/services/<name>/FeatureServer/0/addAttachment?
Can anyone see what I'm missing? Have any insights?
Thank you
Good morning Eric,
Some insights:
(From the documentation:
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:
https://services.myserver.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/818654/addAttachment
... but further explanation is missing)
I don't know if you are into Python, but you might be interested in the work of Caleb Mackey, who is the author of restapi, a Python API for working with ArcGIS REST Services, which is actively maintained on https://github.com/Bolton-and-Menk-GIS/restapi
Please let us know your solution, when you have found it.
HTH,
Egge-Jan
Hi Egge-Jan Pollé, thanks for the reply...
Example:
- I use the POST method from our previous conversation to create a feature
- The response I receive is:
{ "addResults": [ { "objectId": 23, "uniqueId": 23, "globalId": "7A8A55E9-D95D-4341-ADBE-52632EA46DAB", "success": true } ] }
- Of these, ObjectId, UniqueId, GlobalId, which one is the "FeatureId" required for the addAttachments action?
This document was generated from the following discussion: How to POST using addAttachment?
Michelle Mathias do you know if Eric found a way to get the three POST requests working? If there are still unanswered questions here I would recommend creating a case with Esri Support - Support will be able to take a closer look at and troubleshoot the specific workflows.
Thanks,
Peter
I have not used this site for 2 years. The interface has been changed a lot. I would like to know where I can post (JavaScript related) threads. Thanks.
Hey @ShaningYu - welcome back! The site did recently get a major upgrade. You can post JavaScript related threads to the ArcGIS API for JavaScript channel. Hope this helps, -Peter