Using the Upload API Endpoint Using the Upload API Endpoint

Using the Upload API Endpoint

It's possible to upload local files to the platform using the Upload API Endpoint using a POST request, sending the video file as binary in the payload. 

  1. Using Insomnia/Postman
  2. Python Script Example

To get familiar with the endpoint we recommend testing the endpoint with Insomnia, Postman, or a similar tool. 

Note: At the moment, only local files are supported by the endpoint

Using Insomnia/Postman

To upload a video using Insomnia, you have to set the body as multipart and add the file and all the other necessary parameters.  

The upload[file] parameter needs to be changed to type 'File' using the small arrow at the right side of the row.

The Multipart body should look similar to the sample image.

Screen Shot 2020-10-10 at 16.31.24.png

 

The response of the API will be a '201 - Created' with the JSON of the new video object as Body.

Screen Shot 2020-10-10 at 16.43.11.png

 

Python Script Example:

This a quick sample of a python script using the requests and requests_toolbelt libraries to create the multipart body and send the POST request. The clint library is used for monitoring the upload.

import requests
from clint.textui.progress import Bar as ProgressBar # Library to monitor the upload
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor

# Optional callback to monitor the upload
def create_callback(encoder):
encoder_len = encoder.len
bar = ProgressBar(expected_size=encoder_len, filled_char='■')
def callback(monitor):
bar.show(monitor.bytes_read)
return callback

file_path = '/Users/user/video.mp4' # file path
api_key = 'YOUR_API_KEY' # You API_key

try:
file = open(file_path, 'rb')

# Sample Payload
e = MultipartEncoder({'upload[file]': (file.name, file, 'application/octet-stream'),
'upload[active]': 'True',
'upload[title]': 'Title From Python - Monitored with bar'})

callback = create_callback(e)
payload = MultipartEncoderMonitor(e, callback)
url = "https://uploads.zype.com/uploads?api_key={}".format(api_key)

print('Uploading {}'.format(file.name))
r = requests.post(url, data=payload, headers={'Content-Type': payload.content_type})
except Exception as x:
print('Status: Error ', x)
else:
print('Status: Success ', r.status_code)
print(r.json())