I'm trying to upload a photo using the code below based on ArcGIS Python API:
def handle_attachments_api(
portal_domain: str,
portal_username: str,
portal_password: str,
data_type: str = None,
data_url: str = None,
filename: str = None,
type_keywords: str = None,
description: str = None,
title: str = None,
url: str = None,
text: str = None,
tags: str = None,
snippet: str = None,
extent: str = None,
spatial_reference: str = None,
access_information: str = None,
license_info: str = None,
culture: str = None,
comments_enabled: bool = True,
access: str = None,
overwrite: bool = False,
data: str = None,
thumbnail: str = None,
metadata: str = None,
owner: str = None,
folder: str = None,
item_id: guid = None,
):
gis = GIS(
url=f"https://{portal_domain}/portal",
username=portal_username,
password=portal_password
)
item_properties = {
"type": data_type,
"dataUrl": data_url,
"filename": filename,
"typeKeywords": type_keywords,
"description": description,
"title": title,
"url": url,
"text": text,
"tags": tags,
"snippet": snippet,
"extent": extent,
"spatialReference": spatial_reference,
"accessInformation": access_information,
"licenseInfo": license_info,
"culture": culture,
"commentsEnabled": comments_enabled,
"access": access,
"overwrite": overwrite,
}
gis.content.add(
item_properties=item_properties,
data=data,
thumbnail=thumbnail,
metadata=metadata,
owner=owner,
folder=folder,
item_id=item_id
)
But I see the error below when I use 'jpg' as item type:
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site->packages\arcgis\gis\__init__.py:6837: in add
> itemid = self._portal.add_item(
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site->packages\arcgis\gis\_impl\_portalpy.py:438: in add_item
> resp = self.con.post(path, postdata, files)
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site->packages\arcgis\gis\_impl\_con\_connection.py:1524: in post
> return self._handle_response(
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site->packages\arcgis\gis\_impl\_con\_connection.py:1000: in _handle_response
> self._handle_json_error(data["error"], errorcode)
>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>self = <arcgis.gis._impl._con._connection.Connection object at 0x0000026A223A0B20>
>error = {'code': 400, 'details': [], 'message': 'Item type not valid.', 'messageCode': >'CONT_0113'}
>errorcode = 400
>
> def _handle_json_error(self, error, errorcode):
> errormessage = error.get("message")
> # handles case where message exists in the dictionary but is None
> if errormessage is None:
> errormessage = "Unknown Error"
> # _log.error(errormessage)
> if "details" in error and error["details"] is not None:
> if isinstance(error["details"], str):
> errormessage = f"{errormessage} \n {error['details']}"
> # _log.error(error['details'])
> else:
> for errordetail in error["details"]:
> if isinstance(errordetail, str):
> errormessage = errormessage + "\n" + errordetail
> # _log.error(errordetail)
>
> errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
> raise Exception(errormessage)
>E Exception: Item type not valid.
>E (Error Code: 400)
>
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site->packages\arcgis\gis\_impl\_con\_connection.py:1023: Exception
Where I can see a list of all allowed items type?
On your
item_properties = {
"type": data_type,
...
}
change the type to "Image"
.