From 19ea5c104f761dd41088d2f719da66414b4da652 Mon Sep 17 00:00:00 2001 From: Harmon Date: Tue, 12 Jan 2021 21:28:29 -0600 Subject: [PATCH] Handle upload chunk size in bytes --- tweepy/api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index c50e0e1..3eb1be4 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -281,19 +281,19 @@ class API: min_chunk_size, remainder = divmod(file_size, 1000) min_chunk_size += bool(remainder) - # Default chunk size, in kibibytes, 1 MB is given as example chunk size in Twitter API docs + # Default chunk size, in bytes, 1 MB is given as example chunk size in Twitter API docs # The max is given in the docs as 5 MB. - chunk_size = kwargs.pop('chunk_size', 1024) - chunk_size = max(min(chunk_size, 5 * 1024), min_chunk_size) + chunk_size = kwargs.pop('chunk_size', 1024 * 1024) + chunk_size = max(min(chunk_size, 5 * 1024 * 1024), min_chunk_size) - segments, remainder = divmod(file_size, chunk_size * 1024) + segments, remainder = divmod(file_size, chunk_size) segments += bool(remainder) for segment_index in range(segments): # The APPEND command returns an empty response body self.chunked_upload_append( media_id, - (os.path.basename(filename), fp.read(chunk_size * 1024)), + (os.path.basename(filename), fp.read(chunk_size)), segment_index, *args, **kwargs ) -- 2.25.1