Skip to content

Allow streaming uploads to S3. #1813

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

Merged
merged 1 commit into from
Aug 29, 2019
Merged

Conversation

smarnach
Copy link
Contributor

Currently the interface in the s3 crate accepts the contents of an upload as a byte slice, which
so far isn't much of a problem, since crate uploads are generally below 10MB. When uploading public
database dumps to S3 (#1800), however, we don't want to keep the whole dump in memory at once.

This change basically changes the type of the uploaded content from &[u8] to a generic type
implementing std::io::Read + Send + 'static, which are the trait bounds reqwest requires for the
request body.

The PUT request to S3 needs to include a Content-Length header. Since a std::io::Read does not
have a length, we need to add another parameter for the content length, and pass it on to reqwest.

Currently the interface in the `s3` crate accepts the contents of an upload as a byte slice, which
so far isn't much of a problem, since crate uploads are generally below 10MB. When uploading public
database dumps to S3 (rust-lang#1800), however, we don't want to keep the whole dump in memory at once.

This change basically changes the type of the uploaded content from `&[u8]` to a generic type
implementing `std::io::Read + Send + 'static`, which are the trait bounds `reqwest` requires for the
request body.

The PUT request to S3 needs to include a Content-Length header. Since a `std::io::Read` does not
have a length, we need to add another parameter for the content length, and pass it on to `reqwest`.
@rust-highfive
Copy link

r? @jtgeibel

(rust_highfive has picked a reviewer for you, use r? to override)

/// It returns a a tuple containing the path of the uploaded file
/// and its checksum.
pub fn upload(
/// It returns the path of the uploaded file.
Copy link
Contributor Author

@smarnach smarnach Aug 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, the return value is never used, so we could completely get rid of it, but I conservatively kept it for now.

@sgrif
Copy link
Contributor

sgrif commented Aug 29, 2019

@bors: r+

@bors
Copy link
Contributor

bors commented Aug 29, 2019

📌 Commit 44c93be has been approved by sgrif

bors added a commit that referenced this pull request Aug 29, 2019
Allow streaming uploads to S3.

Currently the interface in the `s3` crate accepts the contents of an upload as a byte slice, which
so far isn't much of a problem, since crate uploads are generally below 10MB. When uploading public
database dumps to S3 (#1800), however, we don't want to keep the whole dump in memory at once.

This change basically changes the type of the uploaded content from `&[u8]` to a generic type
implementing `std::io::Read + Send + 'static`, which are the trait bounds `reqwest` requires for the
request body.

The PUT request to S3 needs to include a Content-Length header. Since a `std::io::Read` does not
have a length, we need to add another parameter for the content length, and pass it on to `reqwest`.
@bors
Copy link
Contributor

bors commented Aug 29, 2019

⌛ Testing commit 44c93be with merge 6b63a1c...

@bors
Copy link
Contributor

bors commented Aug 29, 2019

☀️ Test successful - checks-travis
Approved by: sgrif
Pushing 6b63a1c to master...

@bors bors merged commit 44c93be into rust-lang:master Aug 29, 2019
@bors bors mentioned this pull request Aug 29, 2019
9 tasks
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.

5 participants