Prerequisites

  • You have an API key. If not, you can get one by contacting us.
  • You have python installed on your machine along with the requests library

Steps

Large files can be uploaded directly to our S3 bucket. You first request for a presigned post url, upload your file there, then initialize it as a resource.

Step 1: Get an upload URL

In addition to the upload url, it also contains additional fields you must pass in to the url.

Python
import sys
import requests
import json

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

data = {
    'resource_type': 'video', # One of the 5 types
    'content_type': 'video/mp4'
}

# Make the POST request
helper_response = requests.get(
  base_url + "/resources/upload-helper",
  params=data,
  headers=headers
)

# Check the response
if helper_response.status_code != 200:
    print(f'Failed to upload file. Status code: {helper_response.status_code}')
    print('Response:', helper_response.text)
    sys.exit(1)
print('Get successful', helper_response.json())

Step 2: Upload your file to the returned URL

It’s important to note that the URL returned in the previous step is only valid for a short period of time. You should upload your file as soon as possible after receiving the URL.

Python
files = {
  'file': ('video.mp4', open('video.mp4', 'rb'))
}

# Send the post request
upload_response = requests.post(
  helper_response.json()['upload_url'],
  data=helper_response.json()['fields'], # The additional fields
  files=files
)

# Check the response
if upload_response.status_code not in [200, 204]:
    print(f'Failed to upload file. Status code: {upload_response.status_code}')
    print('Response:', upload_response.text)
    sys.exit(1)
print('Upload successful')
Python
# Create resource
body = {
    "resource_name": "workshop-video",  # Descriptive name
    "resource_type": "video",  # One of the 5 types
    "link": helper_response.json()['upload_url'] + helper_response.json()['fields']['key']
}

response = requests.post(
  base_url + "/resources/from-link",
  json=body,
  headers=headers
)

# Check the response
if response.status_code != 200:
    print(f'Failed to create resource. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)
print('Create resource successful', response.json())
# Contains resource_id which should be noted