<?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 Item does not have a file (error 500) when adding a PNG file to portal using add item operation in ArcGIS REST APIs and Services Questions</title>
    <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/item-does-not-have-a-file-error-500-when-adding-a/m-p/1224703#M4312</link>
    <description>&lt;P&gt;I want to add 8 PNG images using the "Add Item" operation within the REST API to me enterprise portal. I am following this documentation:&amp;nbsp;&lt;A href="https://developers.arcgis.com/rest/users-groups-and-items/add-item.htm" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/rest/users-groups-and-items/add-item.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Currently my script uploads the item to the portal and i also get a success response with the item id&amp;nbsp; but when i try to download the file or share it then it open a page saying "Item does not have a file . Error 500" . My whole idea of adding the images is to share it with other users and update images on daily basis. How can i properly add these images to the portal through REST API:&amp;nbsp; Here is my current code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def add_item(username,File):
    """
    Deelte an existing item from portal
    
    Input:
        - item_id: id of the item to be removed from the portal
        - username: username of user which has uploaded the item

    Return:
        - Flag with a list of messages 
    
    """
    # set request header authorization type
    header = {
        'Authorization': f'Bearer {token}'
    }

    # build url
    u_rl = f"{portal}/sharing/rest/content/users/{username}/addItem"
    req = requests.post(url=u_rl, headers=header,data={"files":File,"filename":"asdas","f": "json","title":"Myfile","item_type":"file","type":"Image","verify":False})
    print(req.json())

    
if __name__ == "__main__":
    user = input("input your USERNAME: ")
    password = getpass.getpass("input your PASSWORD: ")
    portal = "https://my/portal"
    token = generate_token(user, password, portal=portal)
    item = r'C:\Users\arcgis\test.png'
    uploadFile = open(item, "rb")
    File= {'file':uploadFile}
add_item(user,File)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 15:20:29 GMT</pubDate>
    <dc:creator>RehanChaudhary</dc:creator>
    <dc:date>2022-10-26T15:20:29Z</dc:date>
    <item>
      <title>Item does not have a file (error 500) when adding a PNG file to portal using add item operation</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/item-does-not-have-a-file-error-500-when-adding-a/m-p/1224703#M4312</link>
      <description>&lt;P&gt;I want to add 8 PNG images using the "Add Item" operation within the REST API to me enterprise portal. I am following this documentation:&amp;nbsp;&lt;A href="https://developers.arcgis.com/rest/users-groups-and-items/add-item.htm" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/rest/users-groups-and-items/add-item.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Currently my script uploads the item to the portal and i also get a success response with the item id&amp;nbsp; but when i try to download the file or share it then it open a page saying "Item does not have a file . Error 500" . My whole idea of adding the images is to share it with other users and update images on daily basis. How can i properly add these images to the portal through REST API:&amp;nbsp; Here is my current code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def add_item(username,File):
    """
    Deelte an existing item from portal
    
    Input:
        - item_id: id of the item to be removed from the portal
        - username: username of user which has uploaded the item

    Return:
        - Flag with a list of messages 
    
    """
    # set request header authorization type
    header = {
        'Authorization': f'Bearer {token}'
    }

    # build url
    u_rl = f"{portal}/sharing/rest/content/users/{username}/addItem"
    req = requests.post(url=u_rl, headers=header,data={"files":File,"filename":"asdas","f": "json","title":"Myfile","item_type":"file","type":"Image","verify":False})
    print(req.json())

    
if __name__ == "__main__":
    user = input("input your USERNAME: ")
    password = getpass.getpass("input your PASSWORD: ")
    portal = "https://my/portal"
    token = generate_token(user, password, portal=portal)
    item = r'C:\Users\arcgis\test.png'
    uploadFile = open(item, "rb")
    File= {'file':uploadFile}
add_item(user,File)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 15:20:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/item-does-not-have-a-file-error-500-when-adding-a/m-p/1224703#M4312</guid>
      <dc:creator>RehanChaudhary</dc:creator>
      <dc:date>2022-10-26T15:20:29Z</dc:date>
    </item>
  </channel>
</rss>

