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.
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.
The response of the API will be a '201 - Created' with the JSON of the new video object as Body.
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())
Was this article helpful?
Articles in this section
- Integrating a Custom Video Player via API
- Create zobjects with custom attributes using the API
- Creating New Subscriptions with the API
- Assigning Categories to Videos Using the API
- Using the Upload API Endpoint
- Ad Timings with the API
- Importing a Single Video from a URL
- How to Merge a New Video Import to an Existing Video Using the API
- How to Request a Video Player