<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Query Feature Layer Feature and Attachment Storage in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1302105#M8817</link>
    <description>&lt;P&gt;Hey I saw your other comment on this &lt;A href="https://community.esri.com/t5/arcgis-online-questions/how-to-get-attachments-size-with-python-script/td-p/1215431" target="_self"&gt;post&lt;/A&gt;&amp;nbsp; which discusses using the attachment manager to find attachment sizes. I would recommend using this, but from your comment it seems the API does not return a very reliable figure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I gave this a quick test with a layer uploaded that is reported as&amp;nbsp;1.316 MB on the attachment size while my notebook returns a value of&amp;nbsp;1381120 which looks about right. Can I just confirm if you did your testing a few hours after uploading any data? I have seen a few cases where the file size reporting in ArcGIS Online takes a few hours to display its true value after edits are made.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2023 16:25:34 GMT</pubDate>
    <dc:creator>David_McRitchie</dc:creator>
    <dc:date>2023-06-22T16:25:34Z</dc:date>
    <item>
      <title>Query Feature Layer Feature and Attachment Storage</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1300000#M8798</link>
      <description>&lt;P&gt;I'm wondering how I can use the Python API to query a feature layer and retrieve the feature and attachment storage separately.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The feature layer property 'size' returns the combined feature and attachment size.&amp;nbsp; I'd like to be able to break the feature and attachment storage separately to better align with the reports generated by AGO.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mpboyle_1-1686863371899.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/73428i3CB88466F7D198E3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mpboyle_1-1686863371899.png" alt="mpboyle_1-1686863371899.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 21:14:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1300000#M8798</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2023-06-15T21:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Query Feature Layer Feature and Attachment Storage</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1302105#M8817</link>
      <description>&lt;P&gt;Hey I saw your other comment on this &lt;A href="https://community.esri.com/t5/arcgis-online-questions/how-to-get-attachments-size-with-python-script/td-p/1215431" target="_self"&gt;post&lt;/A&gt;&amp;nbsp; which discusses using the attachment manager to find attachment sizes. I would recommend using this, but from your comment it seems the API does not return a very reliable figure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I gave this a quick test with a layer uploaded that is reported as&amp;nbsp;1.316 MB on the attachment size while my notebook returns a value of&amp;nbsp;1381120 which looks about right. Can I just confirm if you did your testing a few hours after uploading any data? I have seen a few cases where the file size reporting in ArcGIS Online takes a few hours to display its true value after edits are made.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 16:25:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1302105#M8817</guid>
      <dc:creator>David_McRitchie</dc:creator>
      <dc:date>2023-06-22T16:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Query Feature Layer Feature and Attachment Storage</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1302224#M8820</link>
      <description>&lt;P&gt;The hosted feature layers I've been testing have not been edited since April 2022, so I don't believe that's an issue here.&lt;BR /&gt;&lt;BR /&gt;I did some digging with a few of our hosted feature layers that have a considerable amount of attachments.&amp;nbsp; It seems like the "search" method on the Attachment Manager only returns whatever is the max record count for the service.&amp;nbsp; It doesn't seem to automatically paginate if the max record count is hit.&lt;/P&gt;&lt;P&gt;Using the feature layer above as an example, I should expect a return of around 3GB in size for the attachments.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use the code below, only the first 2,000 attachments are returned...the max record count for the hosted feature layer service.&amp;nbsp;&amp;nbsp;Even if I pass in a value of 9,999 for the "max_records" parameter used by the "search" method, only the first 2,000 attachments are returned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis

itemId = '...'

# connect to portal
p = arcgis.GIS('...')

# set item object
item = p.content.get(itemId)
# get item layers
layers = item.layers
# set place holders
attachmentSize = 0
attachmentCount = 0
# iterate over item layers
for l in layers:
    # check if layer supports attachments
    attachmentSupport = l.properties.hasAttachments
    if attachmentSupport:
        attachments = l.attachments.search(where='1=1')
        # iterate over attachments
        for a in attachments:
            attachmentCount += 1
            s = a.get('SIZE')
            attachmentSize += s

# convert attachment size to MB
attachmentSizeMB = ((float(attachmentSize) / 1024.0) / 1024.0)

print(f'Attachment Count: {attachmentCount:,}')
print(f'Attachment Size: {attachmentSize:,}')
print(f'Attachment Size (MB): {attachmentSizeMB:,.2f}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mpboyle_0-1687465077363.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/73972iC8FE0F69589A359F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mpboyle_0-1687465077363.png" alt="mpboyle_0-1687465077363.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that in order to retrieve ALL attachments you need to account for pagination/offset when using the Attachment Manager.&amp;nbsp; With the script below, which uses the "max_records" and "offset" parameters, I was able to finally return all attachments and get a similar number that the item page displays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis

itemId = '...'

# connect to portal
p = arcgis.GIS('...')

# set item object
item = p.content.get(itemId)
# get item layers
layers = item.layers
# set place holders
attachmentLoops = 0
attachmentSize = 0
attachmentCount = 0
# iterate over item layers
for l in layers:
    # check if layer supports attachments
    attachmentSupport = l.properties.hasAttachments
    if attachmentSupport:
        # set query values
        attachmentMax = 1000
        attachmentOffset = 0
        continueQuery = True
        # get attachments
        while continueQuery:
            attachmentLoops += 1
            attachments = l.attachments.search(where='1=1', max_records=attachmentMax, offset=attachmentOffset)
            # check for attachments
            if attachments:
                # increment offset
                attachmentOffset += attachmentMax
                # iterate over attachments
                for a in attachments:
                    attachmentCount += 1
                    s = a.get('SIZE')
                    attachmentSize += s
            else:
                continueQuery = False
        
# convert attachment size to MB
attachmentSizeMB = ((float(attachmentSize) / 1024.0) / 1024.0)
# check attachment loops
if attachmentLoops == 0:
    attachmentLoops = 0
else:
    attachmentLoops = attachmentLoops - 1

print(f'Number of Loops: {attachmentLoops:,}')
print(f'Attachment Count: {attachmentCount:,}')
print(f'Attachment Size: {attachmentSize:,}')
print(f'Attachment Size (MB): {attachmentSizeMB:,.2f}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mpboyle_1-1687465570032.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/73977iE0B394DE442CCE32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mpboyle_1-1687465570032.png" alt="mpboyle_1-1687465570032.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 21:33:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1302224#M8820</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2023-06-22T21:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Query Feature Layer Feature and Attachment Storage</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1303059#M8829</link>
      <description>&lt;P&gt;Ah that explains! In my test layers the record count was below 2000 records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for pasting your code. That should be really useful for anyone else encountering this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 16:19:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1303059#M8829</guid>
      <dc:creator>David_McRitchie</dc:creator>
      <dc:date>2023-06-26T16:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Query Feature Layer Feature and Attachment Storage</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1525002#M10456</link>
      <description>&lt;P&gt;I created a script to calculate the file size of hosted feature layers excluding attachments for credit management, based on the code from this post.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-ideas/to-manage-agol-credits-we-will-investigate-which/idi-p/1524399" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-ideas/to-manage-agol-credits-we-will-investigate-which/idi-p/1524399&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 11:25:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-feature-layer-feature-and-attachment-storage/m-p/1525002#M10456</guid>
      <dc:creator>MasaakiKurokawa</dc:creator>
      <dc:date>2024-08-21T11:25:58Z</dc:date>
    </item>
  </channel>
</rss>

