-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Rework media uploading #1486
Rework media uploading #1486
Conversation
* And safe import urllib in both py2/3 * rename methods to match API * DRY max sizes, put in class in case twitter changes them * use single media_upload for image and video, send to standard or * chunked upload based on mime type and size * finalize needs ModelParser, not RawParser
Add minimum chunk size of 16K, keeps number of chunks under 999
Adds video upload
Add and use additional_owners, file, filename, and media_category documented parameters
So as to refer to uploading media rather than only images
@LuisMayo As per our discussion in #1414, I've added a |
This branch/pull request should be complete now. Any feedback and/or review from @Choko256, @fitnr, @jamesandres, @jamiewinspear, @LuisMayo, @Maradonna90, or anyone else would be appreciated. |
The code looks a lot cleaner to me. Worked perfectly in a quick manual test. |
This pull request adds
API.simple_upload
,API.chunked_upload_init
,API.chunked_upload_append
,API.chunked_upload_finalize
, andAPI.get_media_upload_status
. It also addsAPI.chunked_upload
, which callsAPI.chunked_upload_init
,API.chunked_upload_append
, andAPI.chunked_upload_finalize
, as well asAPI.get_media_upload_status
when thewait_for_async_finalize
parameter is set, and handles the entire chunked upload process.API.simple_upload
uses the simple image upload endpoint asAPI.media_upload
did, whileAPI.media_upload
now calls eitherAPI.simple_upload
orAPI.chunked_upload
, depending on whether thechunked
parameter is set and if the media being uploaded is a video.With support for chunked upload, this allows for uploading videos and large GIFs, which resolves #640 and resolves #1501, respectively.
Media upload methods now use the
data
andfiles
parameters of the requests library'sSession.request
, replacingAPI._pack_image
, which has now been removed.Additionally, there are numerous other improvements, optimizations, etc. to the media upload API methods.
This pull request is based on #655, #672, #929, and #1414, with contributions from @Choko256, @fitnr, @jamesandres, @jamiewinspear, and @Maradonna90, but I've refactored/removed/rewritten almost all of the code from those pull requests.