Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Created April 5, 2020 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DmitrySoshnikov/2027a83bab8f00196d2ec295db1a40a8 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/2027a83bab8f00196d2ec295db1a40a8 to your computer and use it in GitHub Desktop.
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