From 380e83087447b724458ba16e11f527babb39dd01 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Fri, 14 Feb 2014 12:52:26 +0100 Subject: 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 --- swiftclient/client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index 73baa3b..d4f83f1 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -935,7 +935,12 @@ def put_object(url, token=None, container=None, name=None, contents=None, yield data conn.putrequest(path, headers=headers, data=chunk_reader()) else: - conn.putrequest(path, headers=headers, files={"file": contents}) + # Fixes https://github.com/kennethreitz/requests/issues/1648 + try: + contents.len = content_length + except AttributeError: + pass + conn.putrequest(path, headers=headers, data=contents) else: if chunk_size is not None: warn_msg = '%s object has no \"read\" method, ignoring chunk_size'\ -- cgit v1.2.1