Python Forum

Full Version: upload image with generated code from Postman does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to upload an image and set it to profiles of my teammates in some system. I managed to perform this request and upload the images successfully using Postman but unfortunately it doesn't work when copying the generated code/writing it by myself in the IDE...

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"PATH/TO/IMAGE.JPG\"\r\nContent-Type: text/plain\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'Authorization': "Basic
xxxxxxxxxxxxxxxxxxxxxxxxxxx",
'Accept': "*/*",
'Cache-Control': "no-cache",
'Host': "<host.of.site>",
'Content-Type': "multipart/form-data; boundary=--------------------------613416014226243256356192",
'Accept-Encoding': "gzip, deflate",
'Content-Length': "259378",
'Connection': "keep-alive",
'cache-control': "no-cache"
}

response = requests.request("POST", url, data=payload, headers=headers)


Here are their required fields from the documentation:


[inline]POST /api/gateway.php/sample/v1/employees/1/photo/ HTTP/1.0
Host: api.x.com
Content-Type: multipart/form-data; boundary=----MultiPart-Mime-Boundary----
Content-Length: 520

------MultiPart-Mime-Boundary----
Content-Disposition: form-data; name="file"; filename="photo.jpg"
Content-Type: text/plain

... binary file data ...

------MultiPart-Mime-Boundary------

No matter what I do, still getting "400". I would be grateful if someone here could help me! that'll be great! Thanks ahead![/inline]