Skip to main content

How do I display feature attachments in the viewer when they are stored as BLOBs?

Comments

8 comments

  • John Nerge
    Alright, this gets a little tricky, but I have been able to get this work. Ultimately you need to dynamically create the attachment image URL, which is in this structure:

     

    MapService URL/layer ID + OBJECTID + /attachments/ + Attachment ID

     

    The way I figured out how to this is by using a one-to-one data link (which I called Photo). This is the tricky part, but basically what it's doing is joining the feature class to the attachment table using their common fields (OBJECTID and REL_OBJECTID) and then grabbing the info from each in order to generate the full URL to the attached photo.

     

    You can use the generic formula above to understand what each piece of the Select part of the query is doing: 

     

    SELECT

     

    'https://MyGISServer.org/arcgis/rest/services/MyMapService/MapServer/MyLayerId/' + CAST(FeatureClass.OBJECTID AS VARCHAR) + '/attachments/' + CAST(AttachmentTable.ATTACHMENTID AS VARCHAR) AS Image

     

    FROM FeatureClass LEFT OUTER JOIN AttachmentTable ON FeatureClass.OBJECTID = AttachmentTable.REL_OBJECTID

     

    WHERE FeatureClass.OBJECTID = @id

     

    Finally, here's what I put in my feature description:

     

    <img src="{Photo.Image}?token={MapServiceToken}" width="100%"></img>

     

    The data link generates the URL for the attached image specific to the record in my feature class, and I'm using the MapServiceToken because it's a secured map service.

     

    Let me know if any of that's unclear. You might have some unique stuff in your feature class, but hopefully if you just update the parts of the query I put in bold then it should work for you.
    0
  • Permanently deleted user
    Thanks John, I tried this, got it to work.

     

    However, I am writing it here for the record that this is NOT a suitable solution for multiple photo attachments. Latitude should consider better support for attachments, blobs, related records, etc.
    0
  • Michael Wallace
    Hello John

     

    I understand the query but how do I set up the data link. 

     

    I have to add a data connection but there isn't an option for a Feature Set, JSON or a web link? 

     

    Sincerely,

     

     

    Michael Wallace
    0
  • Permanently deleted user
    OK,

     

    SDE and ArcGIS Server Verison = 10.5.1, Essentials 4.9.1.37

     

    I think I have found a bit simpler way to accomplish this. I could have not gotten here so quickly without John's logic, so thank you. I encourage users to link their attachments like this:

     

    Create a very simple data link (I called mine Photos):

     

    SELECT ATTACHMENTID FROM YourTable__ATTACH_evw WHERE REL_GLOBALID = @ID (My attachment table was related by GlobalID, aren't they all?)

     

    Datalink to the "versioned view" ATTACH table in SDE, this way you will always have all the attachment information, even in an uncompressed state. The "@ID" variable is the GlobalID of the FC that has attachments. Very simple. The only field you need is ATTACHMENTID.

     

    Put this in your Feature Description:

     

    <img src="http://yourserver/arcgis/rest/services/YourService/MapServer/{LayerId}/{OBJECTID}/attachments/{Photos.ATTACHMENTID}?token={MapServiceToken}" height="300" width="300">

     

    Using this data link method, you can build your URL to the attachments Geocortex Replacement Tokens. You only need the datalink to get the ATTACHMENTID. This way nothing is "Hard Coded", so if your LayerID changes, you don't have to worry about the link breaking. 

     

    Thank you, everyone, for your contributions to this discussion. This solution ended up being really simple.
    0
  • Permanently deleted user
    Hello Patrick, 

     

    may you post a short video or images sequence of the main steps of the method?

     

    Thank you so much.
    0
  • Permanently deleted user
    Thanks to Patrick and John's response we can display photos and audio within the feature description.

     

    However some of our features do not contain photos, so the viewer displays a broken thumbnail:

     

    _img_ alt="User-added image" src="https://latitudegeo--c.na53.content.force.com/servlet/rtaImage?eid=907f2000000XevY&feoid=Body&refid=0EMf2000000YFH9"_/_img_

     

    It was be nice to display an alternative image when a photo attachment is not associated with the feature.

     

    I have tried adjusting the feature description html using the 'onerror' tag with no luck in the viewer (it still just display the broken thumbnail - as above). The html I have tried adding in is:

     

    <img src="http://yourserver/arcgis/rest/services/YourService/MapServer/{LayerId}/{OBJECTID}/attachments/{Photos.ATTACHMENTID}?token={MapServiceToken}" height="300" width="300" onerror="this.src = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/300px-No_image_available.svg.png';">

     

    This produce the result I am after in the 'Edit Feature Long Description' in Essentials Manager but not in the viewer. The problem may be that when in the viewer there is no 'onerror' produced as the attempted URL exerts through to the point of the  /{OBJECTID}/attachments/ (not an error).

     

    If anyone had any ideas on this nice to have that would be great. 

     

     
    0
  • John Nerge
    I use an admittedly janky method to handle records that don't have a photo. Basically, when there's no attachment, I still load a photo in the feature description, which is a white rectangle (https://c2.staticflickr.com/6/5613/30843088585_22aebcacca_c.jpg). That takes care of the broken link issue, and for all intents and purposes the map tip looks blank to the user since the rectangle is the same color as the background.

     

    Quick background

     

    I'm using the data link described back in 2017 in an Adopt a Hydrant app where along with adopting a hydrant people can submit photos of their hydrants dressed up in costumes (part of an annual city competition). Here's the app (search for Captain Rex to see a hydrant with a photo): https://gis.brooklynpark.org/adoptahydrant/

     

    Because we want to review the submitted photos before making them public, we have PhotoStatus field we update with our workflows that equals No Photo, Pending, or Approved. We use that field in our data link with a CASE statement to determine what photo to display. If there's no photo, the data link passes a URL to the white rectangle, if it's pending it passes a photo that says Photo Pending, and if approved it passes the actual photo.

     

    That specific method requires a PhotoStatus field, but if you're dealing with a feature layer that simply either has photos or not, you can still use a CASE statement and a the placeholder photo.

     

    The method

     

    You'd still use a CASE statement, but you'd only need one WHEN and one ELSE. In the snippet below I'm using the ELSE for all features with attachments, but you could also flip it by changing the WHEN statement to be IS NOT NULL.

     

    WHEN AttachmentTable.ATTACHMENTID IS NULL THEN 'https://c2.staticflickr.com/6/5613/30843088585_22aebcacca_c.jpg'

     

    ELSE 'https://MyGISServer.org/arcgis/rest/services/MyMapService/MapServer/MyLayerId/' + CAST(FeatureClass.OBJECTID AS VARCHAR) + '/attachments/' + CAST(AttachmentTable.ATTACHMENTID AS VARCHAR) 

     

    END AS PhotoURL

     

    This is also the explanation for why I generate the full URL using the data link instead of just grabbing the attachment ID. But I do really like Patrick's method and would use that when either every feature had a photo or displaying a broken link was unimportant, such as in internal viewers!
    0

Please sign in to leave a comment.