Select to view content in your preferred language

Append with Attachments

733
2
Jump to solution
10-19-2023 06:02 PM
MicZatorsky_AEC
Frequent Contributor

Hi all.

What is the recommended workflow to append records with photo attachments to an empty survey such that the attachments know which field they belong to?

The Append tool in Pro successfully inserts the records and maintains attachments into the hosted feature layer, but Feature Reports do not show the photos.  I understand this has something to do with attachment keywords?   I have from 1 to 4 photos for each record, each belonging to one of four individual photo fields (photo1, photo2, photo3, photo4)

I'm using ArcGIS Online and ArcGIS Pro 3.1.3 

Thanks

0 Kudos
1 Solution

Accepted Solutions
Raul
by
Regular Contributor

The key to getting the Survey123 report to recognize an uploaded image to a specific (survey123) image field, is for the uploaded image to have the name of the image field on the 'Keywords' property of the attachment.

Capture.PNG
I don't think there's currently any way to specify this property either through ArcGIS pro, nor the built in add attachment functionality on AGOL/ Portal for ArcGIS.

However, you CAN specify this parameter either in the ArcGIS Rest API:
https://developers.arcgis.com/rest/services-reference/enterprise/add-attachment.htm

Or using the ArcGIS API for Python - AttachmentManager.add()
https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#attachmentmanager

I've included a very simple python script as a sample of how it may be used.

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features.managers import AttachmentManager

def main():
    # Portal configuration
    portal_url = "https://www.arcgis.com"
    username = 'your_username'
    passw = 'your_password'

    # REST endpoint of service where to add image
    rest_url = 'https://services1.arcgis.com/.../ArcGIS/rest/services/.../FeatureServer/0'

    # Name of image field in SURVEY where image uploaded should be associated to
    img_field_name = 'photos_1'

    # Path to photo to be uploaded
    img_path = r'D:\Pictures\Stock\DVC6xnOAzZg.jpg'

    # Object Id of feature to attach image to
    oid_feature = 2

    # Create a GIS instance
    print('Attempting to login to ArcGIS [...]')
    gis = GIS(portal_url, username, passw)

    # Upload photo
    try:
        print('Uploading image [...]')
        fl = FeatureLayer(rest_url, gis)

        attachments_mgr = AttachmentManager(fl)
        res = attachments_mgr.add(oid_feature, img_path, keywords=img_field_name)
        if(res and res['addAttachmentResult'] and res['addAttachmentResult']['success']):
            print('Image uploaded Successfully!')

    except Exception as e:
        print('An error has occurred while attempting to upload the specified phhoto')
        print(repr(e))

if __name__ == "__main__":
    main()

View solution in original post

2 Replies
Raul
by
Regular Contributor

The key to getting the Survey123 report to recognize an uploaded image to a specific (survey123) image field, is for the uploaded image to have the name of the image field on the 'Keywords' property of the attachment.

Capture.PNG
I don't think there's currently any way to specify this property either through ArcGIS pro, nor the built in add attachment functionality on AGOL/ Portal for ArcGIS.

However, you CAN specify this parameter either in the ArcGIS Rest API:
https://developers.arcgis.com/rest/services-reference/enterprise/add-attachment.htm

Or using the ArcGIS API for Python - AttachmentManager.add()
https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#attachmentmanager

I've included a very simple python script as a sample of how it may be used.

from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features.managers import AttachmentManager

def main():
    # Portal configuration
    portal_url = "https://www.arcgis.com"
    username = 'your_username'
    passw = 'your_password'

    # REST endpoint of service where to add image
    rest_url = 'https://services1.arcgis.com/.../ArcGIS/rest/services/.../FeatureServer/0'

    # Name of image field in SURVEY where image uploaded should be associated to
    img_field_name = 'photos_1'

    # Path to photo to be uploaded
    img_path = r'D:\Pictures\Stock\DVC6xnOAzZg.jpg'

    # Object Id of feature to attach image to
    oid_feature = 2

    # Create a GIS instance
    print('Attempting to login to ArcGIS [...]')
    gis = GIS(portal_url, username, passw)

    # Upload photo
    try:
        print('Uploading image [...]')
        fl = FeatureLayer(rest_url, gis)

        attachments_mgr = AttachmentManager(fl)
        res = attachments_mgr.add(oid_feature, img_path, keywords=img_field_name)
        if(res and res['addAttachmentResult'] and res['addAttachmentResult']['success']):
            print('Image uploaded Successfully!')

    except Exception as e:
        print('An error has occurred while attempting to upload the specified phhoto')
        print(repr(e))

if __name__ == "__main__":
    main()
MicZatorsky_AEC
Frequent Contributor

Thanks Raul

0 Kudos