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

feat(upload): add support for streamed uploads of large files #1435

Closed
wants to merge 4 commits into from

Conversation

okhex
Copy link
Contributor

@okhex okhex commented Sep 9, 2024

Streamed uploads

The API also supports streamed uploads, in cases where the length of the file is not known before starting the upload.

This is useful for example when converting a video, to avoid buffering the entire converted video on the filesystem, each part is uploaded immediately as soon as it is produced by the encoder.

Everything works similarly to normal uploads, with a few key differences:

  • The client buffers part_size bytes (or less if the stream ends) before immediately uploading the part as described in the previous section.

  • A total_stream_size variable must be used to keep track of the total number of bytes read from the stream.

  • upload.saveBigFilePart must always be used, even if the stream turns out to be smaller than 10MB.

  • The file_total_parts field must be set to -1 for all parts except for the last one, using the following logic:

  • If the stream ends and the length of the buffered part is bigger than 0, upload it, setting file_total_parts=ceil(total_stream_size/part_size) (like for normal uploads)

  • If the stream ends and the length of the buffered part is equal to 0, upload it anyway (upload one last empty part), setting file_total_parts=ceil(total_stream_size/part_size) (like for normal uploads)

Note that streamed uploads cannot be used when uploading photos with inputMediaUploadedPhoto.

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.04%. Comparing base (ac6bc17) to head (ca17236).
Report is 23 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1435      +/-   ##
==========================================
+ Coverage   71.02%   71.04%   +0.02%     
==========================================
  Files         442      442              
  Lines       17744    17752       +8     
==========================================
+ Hits        12602    12612      +10     
+ Misses       4209     4207       -2     
  Partials      933      933              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@okhex okhex changed the title Added Support For Streamed Uploads feat(upload): add support for streamed uploads of large files Sep 9, 2024
dependabot bot and others added 4 commits September 10, 2024 00:46
Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 6 to 7.
- [Release notes](https://github.com/peter-evans/create-pull-request/releases)
- [Commits](peter-evans/create-pull-request@v6...v7)

---
updated-dependencies:
- dependency-name: peter-evans/create-pull-request
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
@okhex okhex closed this by deleting the head repository Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants