I need to upload a PNG file using an API which says:
The request body accepts multipart/form-data with the key as uploadedFile.
Using Chrome postman plugin, I am able to upload the file using API, this is what I did:
Header: none
Body
type: form-data
key: uploadedFile
Value: <file-location>
POST
This is the Python code that I have written:
login = requests.post(login_url, <other options>)
# above login is successful
upload_url = "Some_Value"
file_path = '/root/sample.png'
file = {'file': ('pngfile', open(file_path, 'rb'), 'image/png')}
body = { 'uploadedFile': file_path}
post_file = requests.post(upload_url, files=file, data=body, cookies=login.cookies, verify=False)
I get the following error:
Bad Request[ errorCode:-18 ,message:Unsupported image file format. Please upload an image in GIF, JPEG or PNG format.]