Select to view content in your preferred language

Upload PNG image using /addItem

442
3
08-17-2023 02:41 PM
julian_svcs
Occasional Contributor

I am trying to upload a PNG file as an item to Portal using /addItem using python post calls.

What format should 'file' be? I have tried converting to a binary image (a whole series of 0's and 1's) and also tried the file path. The item is created but it is "empty".

When I do this manually and look at the dev tools for the '/addItem' post, it is set as 'file: (binary)'. I am not sure how to create the '(binary)' file type using python.

Any help and code examples for this will be great, thanks very much.

Regards, Julian

0 Kudos
3 Replies
David_McRitchie
Esri Contributor

Hey Jilian,

 

Based on the documentation I believe a file path should suffice. Hopefully some of the examples within this help.

Many thanks,

David

Esri UK -Technical Support Analyst
0 Kudos
julian_svcs
Occasional Contributor

Hi Divid. That doesn't work. I tried the path to the file and also tried to convert the image to binary and use that. In both cases it creates the item but it is empty.

I had a look at that website you posted but I don't see where it specifies the file path for 'file' or see anything in the examples.

Here is my json for the data post request:

logo_title = "Logo.png"
logo_path = r"c:\_scripts_\_scratch\{}".format(logo_title)
data_add_item = {
    "title": f"Shared Theme Logo - {os.path.splitext(logo_title)[0]}",
    "description": "This image was uploaded for use as your organization's shared theme logo.",
    "type": "Image",
    "tags": "SharedTheme, Logo",
    "f": "json", 
    "file": logo_path,
    "token": token
}
0 Kudos
freddies
New Contributor

The 'file' parameter is of binary. Anyone know of a way to specify the value/content of this 'file' parameter?

0 Kudos