From addb32e7e14bddf319a33aa4c26687360c1e5cd5 Mon Sep 17 00:00:00 2001 From: Amnisia Date: Tue, 10 Oct 2017 14:07:36 +0500 Subject: [PATCH] fix upload media chunked async method in twitter_utils.parse_media_file --- twitter/api.py | 2 +- twitter/twitter_utils.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/twitter/api.py b/twitter/api.py index 58917c5c..f0082d34 100644 --- a/twitter/api.py +++ b/twitter/api.py @@ -1197,7 +1197,7 @@ def _UploadMediaChunkedInit(self, """ url = '%s/media/upload.json' % self.upload_url - media_fp, filename, file_size, media_type = parse_media_file(media) + media_fp, filename, file_size, media_type = parse_media_file(media, async_upload=True) if not all([media_fp, filename, file_size, media_type]): raise TwitterError({'message': 'Could not process media file'}) diff --git a/twitter/twitter_utils.py b/twitter/twitter_utils.py index 66ce8b24..743cf65e 100644 --- a/twitter/twitter_utils.py +++ b/twitter/twitter_utils.py @@ -190,12 +190,13 @@ def http_to_file(http): return data_file -def parse_media_file(passed_media): +def parse_media_file(passed_media, async_upload=False): """ Parses a media file and attempts to return a file-like object and information about the media file. Args: passed_media: media file which to parse. + async_upload: flag, for validation media file attributes. Returns: file-like object, the filename of the media file, the file size, and @@ -240,8 +241,10 @@ def parse_media_file(passed_media): if media_type is not None: if media_type in img_formats and file_size > 5 * 1048576: raise TwitterError({'message': 'Images must be less than 5MB.'}) - elif media_type in video_formats and file_size > 15 * 1048576: + elif media_type in video_formats and not async_upload and file_size > 15 * 1048576: raise TwitterError({'message': 'Videos must be less than 15MB.'}) + elif media_type in video_formats and async_upload and file_size > 512 * 1048576: + raise TwitterError({'message': 'Videos must be less than 512MB.'}) elif media_type not in img_formats and media_type not in video_formats: raise TwitterError({'message': 'Media type could not be determined.'})