Is it possible to reuse an HTTP Request Body multiple times in Rust without reading it into memory?

If you need to calculate the hash before you upload the file, your only options are

  1. Read the file into memory once, hash it from memory and then upload it from memory
  2. Read the file in chunks twice. Once for calculating the hash, and once for the actual upload.

It sounds like Option 1 isn't feasible for you, which means you're almost certainly going to have to read the file twice to avoid storing the whole thing in memory.

If you actually don't need the hash before the upload is complete, you have more options though. I implemented a simple tokio::io::AsyncRead wrapper for hashing a stream of data in response to another question awhile back. Some details might need to change for actix, I haven't used that before.

1 Like