Python

Simple Python script to upload a capture zip file. It retrieves the authentication token using the client_id and client_secret you can find in your Developer Dashboard.

Read the Quick Start Guide and the Upload Captures pages to learn more.

⚠️ To run this you need httpx. Run pip install httpx to install it.

import sys
import pathlib
import httpx

CLIENT_ID = 'insert-it-here'
CLIENT_SECRET = 'insert-it-here'

AUTH_ENDPOINT = 'https://signin.teleport.varjo.com/oauth2/token'

API_BASE = 'https://teleport.varjo.com'

# Step 1: Authenticate
auth_response = httpx.post(
    AUTH_ENDPOINT,
    data = {
        'grant_type': 'client_credentials',
        'client_id': CLIENT_ID,
        'client_secret': CLIENT_SECRET,
        'scope': 'openid profile email'
    }
)
auth_response.raise_for_status()

access_token = auth_response.json()['access_token']

# Step 2: Prepare the capture file
filename = sys.argv[1]
inputfile = pathlib.Path(filename)
bytesize = inputfile.stat().st_size

print(f'Uploading capture of {bytesize} bytes..')

# Step 3: Create capture
created = httpx.post(
    API_BASE + '/api/v1/captures',
    json = {
        'name': inputfile.name,
        'bytesize': bytesize,
        'input_data_format': 'bulk-images'
    },
    headers = {'Authorization': f'Bearer {access_token}'}
)
created.raise_for_status()

eid = created.json()['eid']
num_parts = created.json()['num_parts']
chunk_size = created.json()['chunk_size']
print(f'Uploading {num_parts} parts..')

# Step 4: Upload file parts
fd = inputfile.open('rb')
parts = []
for part_no in range(num_parts):
    url = httpx.post(
        API_BASE + f'/api/v1/captures/{eid}/create-upload-url/{part_no + 1}',
        json = {'eid': eid, 'bytesize': bytesize},
        headers = {'Authorization': f'Bearer {access_token}'}
    )
    url.raise_for_status()
    upload_url = url.json()['upload_url']

    print('Uploading part', part_no)
    part = fd.read(chunk_size)
    put_response = httpx.put(
        upload_url,
        content = part,
        follow_redirects = True,
        timeout = 30.0
    )
    put_response.raise_for_status()
    parts.append({
        'number': part_no + 1,
        'etag': put_response.headers['etag'].strip('"')
    })

# Step 5: Notify upload completion
completed = httpx.post(
    API_BASE + f'/api/v1/captures/{eid}/uploaded',
    json = {'eid': eid, 'parts': parts},
    headers = {'Authorization': f'Bearer {access_token}'}
)
completed.raise_for_status()

print('Upload done!')
print('Capture state:', completed.json()['state'])