I have to use a REST API to upload files and information to a server. That API uses a multipart-form, but I cannot seem to be able to use it correctly.
Here is the information I use according to the API documentation.
Form Parameters:
- description – A short description of the distribution.
- release_notes_url – A url pointing to the release notes.
- zip_file – The ZIP file containing the distribution files.
Example request:
POST /api/v1/distribution HTTP/1.1
Host: api.company.onbe
Authorization: t=...
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryZayrf7leHxinyQsX
------WebKitFormBoundaryZayrf7leHxinyQsX
Content-Disposition: form-data; name="release_notes_url"
http://releases/3.0.0/release_notes_3_0_0.pdf
------WebKitFormBoundaryZayrf7leHxinyQsX
Content-Disposition: form-data; name="description"
This is the new distribution!
------WebKitFormBoundaryZayrf7leHxinyQsX
Content-Disposition: form-data; name="zip_file"; filename="BackEnd-3.0.0.zip"
Content-Type: application/x-zip-compressed
------WebKitFormBoundaryZayrf7leHxinyQsX--
I tried several things, like the following code for example, but I keep getting bad request errors from the server.
import requests
file= open('BackEnd-3.0.0.zip','r').read()
url = 'api.company.onbe/api/v1/distribution'
payload = {
'description' :'Some desc',
'release_notes_url':'Someurl.pdf',
'zip_file': file
}
response = requests.post(url, data=payload)