question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding attachments using layer.edit_features fail

See original GitHub issue

When using layer.edit_features() to add attachments the method fails and returns None. This is caused by your requirement of one of the methods adds, deletes or updates to be part of the call.

layer.py: image

You should add and "attachments" not in params as well.

Until fixed a workaround is to add an empty deletes=""

        _res = _layer.edit_features(deletes="", use_global_ids=True, gdb_version=_ver, attachments={'adds':[_att]})
        print(_res)

Platform (please complete the following information):

  • Python API Version: 2.0.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nanaeaubrycommented, May 6, 2022

@HakonD

Ok I see what you are saying. We will further investigate these issues.

1reaction
HakonDcommented, May 6, 2022

Sure, I trust you to find a suitable feature service and attachment file.

import os
import base64
import uuid
import mimetypes
import arcgis

# File to attach
_attach = "c:/temp/test.txt"
# Create base64 string
with open(_attach,'rb') as _file:
    _data = _file.read()
    _data64 = base64.b64encode(_data).decode('ascii')

# Get a layer and a feature to attach to
_gis = arcgis.GIS('pro')
_ds = "https://your.server/server/rest/services/yourservice/FeatureServer/0"
_layer = arcgis.features.FeatureLayer(_ds, _gis)
_feat = _layer.query(result_record_count=1, return_all_records=False, out_fields='OBJECTID,GlobalID')

# Create attachment
_att = {
    'globalId': str(uuid.uuid4()),
    'parentGlobalId': _feat.features[0].attributes['GlobalID'],
    'contentType': mimetypes.guess_type(_attach)[0],
    'name': os.path.basename(_attach),
    'data': _data64
}

# Add and fail
_res = _layer.edit_features(use_global_ids=True, attachments={'adds':[_att]})
print(_res)

# Add with empty deletes
_res = _layer.edit_features(deletes="", use_global_ids=True, attachments={'adds':[_att]})
print(_res)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To: Retain all attachments when merging hosted feature ...
Right-click the appended feature layer group layer, and select Edit Features > Synchronize local edits to Server. In ArcGIS Online, check the ...
Read more >
Edit feature attachments | ArcGIS Runtime API for .NET
Select features from the feature layer with FeatureLayer.SelectFeatures() . To fetch the feature's attachments, cast to an ArcGISFeature and use ArcGISFeature.
Read more >
Working with Attachments in Apps - YouTube
Attachments are a common way to associate images, videos, and PDFs with specific features in feature layers. These attachments can enhance ...
Read more >
ArcGIS add photos to features "Enable Attachments ... - YouTube
Learn how to enable attachments to your feature class layer to add photos to your features and add files to it using ArcMapThis...
Read more >
Manage hosted feature layers—Portal for ArcGIS
Export data from the hosted feature layer (Allow others to export to different formats); The ability to add attachments to features in hosted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found