Upload API - upload video part example

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