Forked from DmitrySoshnikov/rust-reqwest-stream-example.rs
Created
January 29, 2024 09:49
-
-
Save gauravssnl/1fc86fc20cf941bf4d2c7f7511a17141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let offset = 20000; | |
let chunk_size = 10000; | |
// File handle: | |
let mut handle = BufReader::new(File::open("data.bin").await?); | |
// Set cursor to needed chunk: | |
let mut chunk_stream = handle | |
.bytes() | |
.skip(offset) | |
.take(chunk_size); | |
// Error: the trait `std::convert::From<u8>` is not implemented for `bytes::bytes::Bytes` | |
// See: https://github.com/seanmonstar/reqwest/blob/master/src/async_impl/body.rs#L90 | |
let chunk = multipart::Part::stream(Body::wrap_stream(chunk_stream)); | |
// ^^^^^^^^^^^^^^^ | |
let form = multipart::Form::new() | |
.text("session_id", "<session-id>") | |
.part("chunk", chunk); | |
reqwest::Client::new() | |
.post("<endpoint>")) | |
.multipart(form) | |
.send() | |
.await?; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment