Skip to content

Commit 380e830

Browse files
author
Tristan Cacqueray
committed
Remove multipart/form-data file upload
The requests 'files' parameter adds this 'Content-Type: multipart/form-data' HTTP header and the whole multipart body data get stored with the object. This also create a memory hog issue because files are loaded in memory before being actually sent. This patch removes this behavior and restores what was done before, ie: direct uploading. This patches also fixes an issue in requests, when used with glance CooperativeReader it mis-calculates content-length leading to chunked encoding for raw upload. Change-Id: Ie5b0a1078bedd33f09c6157f48b5f88116c589fa Closes-Bug: #1280072 Closes-Bug: #1280275
1 parent 79f189a commit 380e830

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎swiftclient/client.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,12 @@ def chunk_reader():
935935
yield data
936936
conn.putrequest(path, headers=headers, data=chunk_reader())
937937
else:
938-
conn.putrequest(path, headers=headers, files={"file": contents})
938+
# Fixes https://github.com/kennethreitz/requests/issues/1648
939+
try:
940+
contents.len = content_length
941+
except AttributeError:
942+
pass
943+
conn.putrequest(path, headers=headers, data=contents)
939944
else:
940945
if chunk_size is not None:
941946
warn_msg = '%s object has no \"read\" method, ignoring chunk_size'\

0 commit comments

Comments
 (0)