def __perform_tus_upload(self, filename, attempt): """Take an upload attempt and perform the actual upload via tus. https://tus.io/ Args: attempt (:obj): requests object path (string): path on disk to file filename (string): name of the video file on vimeo.com Returns: string: The Vimeo Video URI of your uploaded video. Raises: VideoUploadFailure: If unknown errors occured when uploading your video. """ upload_link = attempt.get('upload').get('upload_link') try: with io.open(filename, 'rb') as fs: tus_client = client.TusClient('https://files.tus.vimeo.com') uploader = tus_client.uploader(file_stream=fs, url=upload_link) uploader.upload() except Exception as e: raise exceptions.VideoUploadFailure( e, 'Unexpected error when uploading through tus.' ) return attempt.get('uri')
def __perform_tus_upload(self, filename, attempt, chunk_size=DEFAULT_CHUNK_SIZE): """Take an upload attempt and perform the actual upload via tus. https://tus.io/ Args: filename (string): name of the video file on vimeo.com attempt (:obj): requests object chunk_size (int): size of each chunk. defaults to DEFAULT_CHUNK_SIZE Returns: string: The Vimeo Video URI of your uploaded video. Raises: VideoUploadFailure: If unknown errors occured when uploading your video. """ upload_link = attempt.get('upload').get('upload_link') try: with io.open(filename, 'rb') as fs: tus_client = client.TusClient('https://files.tus.vimeo.com') uploader = tus_client.uploader(chunk_size=chunk_size, file_stream=fs, retries=3, url=upload_link) uploader.upload() except Exception as e: raise exceptions.VideoUploadFailure( e, 'Unexpected error when uploading through tus.') return attempt.get('uri')
def _make_pass(self, upload_target, f, size, last_byte): """ Make a pass at uploading. This particular function may do many things. If this is a large upload it may terminate without having completed the upload. This can also occur if there are network issues or any other interruptions. These can be recovered from by checking with the server to see how much it has and resuming the connection. """ response = self.put( upload_target, timeout=None, headers={ 'Content-Length': str(size), 'Content-Range': 'bytes: %d-%d/%d' % (last_byte, size, size) }, data=f) if response.status_code != 200: raise exceptions.VideoUploadFailure( response, "Unexpected status code on upload")