Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

fix upload media chunked async method in twitter_utils.parse_media_file #514

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion twitter/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
7 changes: 5 additions & 2 deletions twitter/twitter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.'})

Expand Down