Skip to content

Commit

Permalink
[bugfix] POST Multipart-Encoded Files
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Jan 3, 2025
1 parent b30438d commit 3fc02bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3fc02bb

Please sign in to comment.