Replace file size check in API.media_upload with chunked parameter
authorHarmon <Harmon758@gmail.com>
Wed, 13 Jan 2021 17:36:11 +0000 (11:36 -0600)
committerHarmon <Harmon758@gmail.com>
Wed, 13 Jan 2021 17:36:11 +0000 (11:36 -0600)
commitc7859b0d9b61096df73d150aeae5071a73429055
treea98aee56c5af7e6ffb58d978b1fa0fd8133f7781
parenta26746ce0bdb16ec0e66a1bc10d1570c886763ac
Replace file size check in API.media_upload with chunked parameter

The simple upload endpoint seems to accept media file sizes much larger than documented, as long as the size after Twitter's API processes the media is below 5 MiB (e.g. through compression, stripping whitespace, etc.). This makes any file size checks prior to uploading to the API potentially overly restrictive.

Regardless of this, MAX_UPLOAD_SIZE_STANDARD was already lower than necessary anyway, as the limit appears to be 5 MiB rather than 5 MB, as the error message when using chunked upload for a file larger than 5 MiB, "File size exceeds 5242880 bytes.", indicates.

The simple upload endpoint seems to consistently respond with a 413 Payload Too Large HTTP response status code when the uploaded file is too large, even after being processed, which should make it fairly apparent that the file is too large.

Most GIFs should be under 5 MiB, but for larger GIFs that the simple upload endpoint will error for, using the chunked parameter will be necessary. Adding this parameter also allows chunked upload of images less than 5 MiB as desired.
tweepy/api.py