Find attachments using task in JavaScript API

4863
3
12-11-2014 02:53 AM
SimonHodge
New Contributor III

Hi,

Does anyone know if it's possible to search for attachments using a task, or if not, any viable work around?  My requirement is that I want to be able to take a text value from the user and then return any attachments with a filename matching the input (or partially containing the input).  A find task allows you to perform the text search on attributes, but attachments don't seem to be an attribute in this way.

The only workaround I can come up with is to return each feature and then make a request to the features endpoint with /attachments?f=json appended and see if a valid attachmentinfo comes back.  This works fine when identifying a small number of features, e.g. where the user has clicked, but isn't viable as a way of searching as it could have to make hundreds or thousands of individual requests.

Thanks

0 Kudos
3 Replies
AdrianMarsden
Occasional Contributor III

Similar here - I have a custom ID task, that doesn't use the templates, it crunches all the results from all the layers into multiple tables then passes this lot over to a popup window (like what ArcIMS did 🙂 )

I have a need to show attachments, but nothing in the results of the ID task shows the presence of attachemts, let alone the actual attachment.

0 Kudos
SimonHodge
New Contributor III


Hi,

I came up with a work around.  First I considered a geoprocessing task and wrote some python that produced a list of attachment names to be returned but this had some downsides.  One being that it required knowing about the location and structure of the geodatabase, which is organised differently from the published service, so you can work out the layer ids the attachments related to.  It was also susceptible to changes made by the GIS team as would need to be manually changed if they moved things around.  Finally, of course, it would only work for map services on our own GIS servers where we can actually write our own geoprocessing tasks.

So, instead I wrote an indexer service.  It's just a C# console application that runs as a Windows service.  It requests the MapServer json for a service to get the list of layers, then for each layer gets the list of object ids then for each object id, gets the attachmentinfo.  If there are attachments, it puts the details in the database.  I then just wrote a WebAPI webservice that queries against this index, rather than directly against the ArcGIS server.  It works really well: the query is very fast and it can index any map service, not just our own.  Of course, the caveat is it's only as up to date as the last time it indexed the service, but that can be done as often as you need.

0 Kudos
ThomasSolow
Occasional Contributor III

I believe you can query attachments using this REST endpoint: ArcGIS REST API 

I don't think the JS API has a wrapper around that, but you can send requests to that route using esri/Request.

0 Kudos