Upload API - upload video part example

Hello,

This is very wishful thinking, but does anyone have an example of uploading a video part using the API? Do I use the API as if it were a multi-part form upload, or the whole body is just the bytes? Or a URL encoded body with POST param of body containing the bytes?

I couldn’t figure it out and I’ve tried various combinations and none seem to work or I get timeouts. So does anyone have an example in any programming language?

Thanks!

Ollie

Hey, @ollieparsley!

One thing to note: the correct URL parameter is part and not index. This is an error in the docs that someone pointed out right before the holidays, and I’m fixing it soon. Sorry for that!

Python example:

CHUNKSIZE = 10 * 1024 * 1024 # 10MB chunk size for video parts

def upload_to_twitch(filename, upload_url, upload_token):
  file = open(filename, 'rb')
  index = 0
  while 1:
    chunk = file.read(CHUNKSIZE)
    if not chunk: break
    index += 1
    headers = {'Accept': TWITCH_VERSION_HEADER,
               'Client-ID': TWITCH_CLIENT_ID,
               'Content-Length': str(len(chunk)) }
    params = {'part': index,
               'upload_token': upload_token }
    r = requests.put(upload_url, params=params, data=chunk, headers=headers)
    print 'Completed uploading part ' + str(index)
  file.close()

  headers = {'Accept': TWITCH_VERSION_HEADER,
             'Client-ID': TWITCH_CLIENT_ID }
  params = {'upload_token': upload_token }
  r = requests.post(upload_url + '/complete', params=params, headers=headers)
  return
1 Like

Perfect! Thank you :slight_smile:

I have it working in golang now. Thanks :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.