def run_upload(video_file_path):
    """
    Configures all of the needed upload_parameters and sets up all information pertinent
    to the video to be uploaded.

    :param video_file_path: <str> the absolute path to the video file
    """

    upload_parameters = {
        'file_path': video_file_path,
        'file_size': os.stat(video_file_path).st_size,
        'file_name': os.path.basename(video_file_path)
    }

    try:
        # Setup API client
        jwplatform_client = Client(JW_API_KEY, JW_API_SECRET)

        # Make /videos/create API call with multipart parameter specified
        jwplatform_video_create_response = jwplatform_client.videos.create(
            upload_method='multipart',
            title=upload_parameters['file_name']
        )

    except JWPlatformError:
        logging.exception('An error occurred during the uploader setup. Check that your API keys are properly '
                          'set up in your environment, and ensure that the video file path exists.')
        return

    # Construct base url for upload
    upload_parameters['upload_url'] = '{protocol}://{address}{path}'.format(**jwplatform_video_create_response['link'])

    logging.info('Upload URL to be used: {}'.format(upload_parameters['upload_url']))

    upload_parameters['query_parameters'] = jwplatform_video_create_response['link']['query']
    upload_parameters['query_parameters']['api_format'] = 'json'
    upload_parameters['headers'] = {'X-Session-ID': jwplatform_video_create_response['session_id']}
    # The chunk offset will be updated several times during the course of the upload
    upload_parameters['chunk_offset'] = 0

    # Perform the multipart upload
    with open(upload_parameters['file_path'], 'rb') as file_to_upload:
        while True:
            chunk = file_to_upload.read(BYTES_TO_BUFFER)
            if len(chunk) <= 0:
                break

            try:
                upload_chunk(chunk, upload_parameters)

            # Log any exceptions that bubbled up
            except requests.exceptions.RequestException:
                logging.exception('Error posting data, stopping upload...')
                break
def run_upload ( video_file_path ) : upload_parameters = { 'file_path' : video_file_path , 'file_size' : os . stat ( video_file_path ) . st_size , 'file_name' : os . path . basename ( video_file_path ) } try : jwplatform_client = Client ( JW_API_KEY , JW_API_SECRET ) jwplatform_video_create_response = jwplatform_client . videos . create ( upload_method = 'multipart' , title = upload_parameters [ 'file_name' ] ) except JWPlatformError : logging . exception ( 'An error occurred during the uploader setup. Check that your API keys are properly ' 'set up in your environment, and ensure that the video file path exists.' ) return upload_parameters [ 'upload_url' ] = '{protocol}://{address}{path}' . format ( ** jwplatform_video_create_response [ 'link' ] ) logging . info ( 'Upload URL to be used: {}' . format ( upload_parameters [ 'upload_url' ] ) ) upload_parameters [ 'query_parameters' ] = jwplatform_video_create_response [ 'link' ] [ 'query' ] upload_parameters [ 'query_parameters' ] [ 'api_format' ] = 'json' upload_parameters [ 'headers' ] = { 'X-Session-ID' : jwplatform_video_create_response [ 'session_id' ] } upload_parameters [ 'chunk_offset' ] = 0 with open ( upload_parameters [ 'file_path' ] , 'rb' ) as file_to_upload : while True : chunk = file_to_upload . read ( BYTES_TO_BUFFER ) if len ( chunk ) <= 0 : break try : upload_chunk ( chunk , upload_parameters ) except requests . exceptions . RequestException : logging . exception ( 'Error posting data, stopping upload...' ) break
Configures all of the needed upload_parameters and sets up all information pertinent
    to the video to be uploaded.

    :param video_file_path: <str> the absolute path to the video file