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

Rework media uploading #1486

Merged
merged 119 commits into from
Apr 4, 2021
Merged

Rework media uploading #1486

merged 119 commits into from
Apr 4, 2021

Conversation

Harmon758
Copy link
Member

@Harmon758 Harmon758 commented Dec 28, 2020

This pull request adds API.simple_upload, API.chunked_upload_init, API.chunked_upload_append, API.chunked_upload_finalize, and API.get_media_upload_status. It also adds API.chunked_upload, which calls API.chunked_upload_init, API.chunked_upload_append, and API.chunked_upload_finalize, as well as API.get_media_upload_status when the wait_for_async_finalize parameter is set, and handles the entire chunked upload process. API.simple_upload uses the simple image upload endpoint as API.media_upload did, while API.media_upload now calls either API.simple_upload or API.chunked_upload, depending on whether the chunked 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 and files parameters of the requests library's Session.request, replacing API._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.

@Harmon758 Harmon758 added Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature labels Dec 28, 2020
@Harmon758 Harmon758 added this to the 4.0 milestone Dec 28, 2020
@Harmon758 Harmon758 self-assigned this Dec 28, 2020
@Harmon758 Harmon758 mentioned this pull request Dec 28, 2020
@Harmon758 Harmon758 added Documentation This is regarding the library's documentation Tests This is regarding the library's tests labels Dec 28, 2020
@Harmon758
Copy link
Member Author

@LuisMayo As per our discussion in #1414, I've added a wait_for_async_finalize keyword-only argument for API.chunked_upload that defaults to True. It can also be passed to API.media_upload when setting chunked to True or uploading videos, and it'll be passed along to API.chunked_upload when API.media_upload calls it.

@Harmon758 Harmon758 changed the title Add video upload support Rework media uploading Feb 21, 2021
@Harmon758 Harmon758 marked this pull request as ready for review February 21, 2021 05:21
@Harmon758
Copy link
Member Author

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.

@fitnr
Copy link
Contributor

fitnr commented Feb 21, 2021

The code looks a lot cleaner to me. Worked perfectly in a quick manual test.

@Harmon758 Harmon758 mentioned this pull request Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation This is regarding the library's documentation Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature Tests This is regarding the library's tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API.media_upload still doesn't allow uploading animated GIFs > 5 MB in size. Support video upload
4 participants