-
Notifications
You must be signed in to change notification settings - Fork 645
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
Conversation
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`.
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. |
There was a problem hiding this comment.
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.
@bors: r+ |
📌 Commit 44c93be has been approved by |
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`.
☀️ Test successful - checks-travis |
Currently the interface in the
s3
crate accepts the contents of an upload as a byte slice, whichso 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 typeimplementing
std::io::Read + Send + 'static
, which are the trait boundsreqwest
requires for therequest body.
The PUT request to S3 needs to include a Content-Length header. Since a
std::io::Read
does nothave a length, we need to add another parameter for the content length, and pass it on to
reqwest
.