diff --git a/README.md b/README.md index c21d2ee..9113b22 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ resp = client.post(url="https://httpbin.org/anything", json=json) print(r.text) # POST Multipart-Encoded Files -files = {'file1': open('file1.txt', 'rb').read(), 'file2': open('file2.txt', 'rb').read()} +files = {'file1': open('file1.txt'), 'file2': open('file2.txt')} r = client.post("https://httpbin.org/post", files=files) print(r.text) diff --git a/src/lib.rs b/src/lib.rs index 162efdb..fe125cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -376,9 +376,8 @@ impl Client { // Files if let Some(files) = files { let mut form = multipart::Form::new(); - for (file_name, file_content) in files { - let part = - multipart::Part::bytes(file_content).file_name(file_name.clone()); + for (file_name, file_buf) in files { + let part = multipart::Part::stream(file_buf).file_name(file_name.clone()); form = form.part(file_name, part); } request_builder = request_builder.multipart(form);