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: https://developers.arcgis.com/rest/users-groups-and-items/add-item.htm
Currently my script uploads the item to the portal and i also get a success response with the item id 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: Here is my current code:
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)