Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API.media_upload still doesn't allow uploading animated GIFs > 5 MB in size. #1501

Closed
tanjyeyee opened this issue Jan 16, 2021 · 4 comments · Fixed by #1486
Closed

API.media_upload still doesn't allow uploading animated GIFs > 5 MB in size. #1501

tanjyeyee opened this issue Jan 16, 2021 · 4 comments · Fixed by #1486
Labels
API This is regarding Twitter's API Bug This is regarding a bug with the library Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature
Milestone

Comments

@tanjyeyee
Copy link

tanjyeyee commented Jan 16, 2021

I've updated my Tweepy to the latest version (3.10.0).

When I try to upload an animated GIF that's larger than 5 MB, I get the following error:

TweepError([{'code': 324, 'message': 'Image file size must be <= 5242880 bytes'}])

Which is super-strange, because I dove into api.py and confirmed that it should allow animated GIFs up to 15 MB in size.

My files are definitely GIF mimetype, file extension .gif.

I also did this:

import imghdr

print(imghdr.what('<path to my GIF file>')

It spit out 'gif' and so should allow a higher file size limit in both media_upload() and also _pack_image() in api.py.

Am I missing something here?

@tanjyeyee tanjyeyee reopened this Jan 19, 2021
@tanjyeyee
Copy link
Author

Actually, I discovered that the error occurred because Tweepy uses the wrong endpoint to try to upload GIFs >5 MB in size.

According to the Twitter API documentation, you have to use chunked media upload to upload larger GIFs, instead of the regular media upload endpoint: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload

("Please note that to upload videos or GIFs (tweet_video, amplify_video, and tweet_gif), you need to use the chunked upload end-point.")

Can someone fix this bug?

@Harmon758 Harmon758 linked a pull request Jan 19, 2021 that will close this issue
@Harmon758 Harmon758 added API This is regarding Twitter's API Bug This is regarding a bug with the library Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature labels Jan 19, 2021
@Harmon758 Harmon758 added this to the 4.0 milestone Jan 19, 2021
@Harmon758
Copy link
Member

The video-upload branch / pull request #1486 should resolve this and should be complete now.
Any feedback or review would be appreciated.

@pifragile
Copy link

still having this issue, any update? i installed tweepy directly from github:
pip install git+https://github.com/tweepy/tweepy.git

i use the following code:

	media_id = api.media_upload('XYZ.gif').media_id
	api.update_status(status, media_ids=[media_id])

and i get:

tweepy.errors.BadRequest: 400 Bad Request
324 - Image file size must be <= 5242880 bytes

@Harmon758
Copy link
Member

That is an error from Twitter and is different from this issue involving chunked media upload.

From the Animated GIF recommendations section of the Twitter API documentation's Media Best Practices guide for uploading media:

In order to process larger GIFs, use the chunked upload endpoint with the media_category parameter. This allows the server to process the GIF file asynchronously, which is a requirement for processing larger files. Pass media_category=tweet_gif to enable async upload behavior for Tweets with an animated GIF.

For more information, see that section and the Media Categories section of that documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API This is regarding Twitter's API Bug This is regarding a bug with the library Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants