You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/11/01 23:42:52 UTC

svn commit: r1196339 - /libcloud/trunk/libcloud/storage/base.py

Author: tomaz
Date: Tue Nov  1 22:42:52 2011
New Revision: 1196339

URL: http://svn.apache.org/viewvc?rev=1196339&view=rev
Log:
Modify _upload_object so it also supports iterators and works with providers which don't support chunked encoding.

Modified:
    libcloud/trunk/libcloud/storage/base.py

Modified: libcloud/trunk/libcloud/storage/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/base.py?rev=1196339&r1=1196338&r2=1196339&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/base.py (original)
+++ libcloud/trunk/libcloud/storage/base.py Tue Nov  1 22:42:52 2011
@@ -523,14 +523,27 @@ class StorageDriver(BaseDriver):
                     'File content-type could not be guessed and' +
                     ' no content_type value provided')
 
+        file_size = None
+
         if iterator:
-            headers['Transfer-Encoding'] = 'chunked'
-            upload_func_kwargs['chunked'] = True
+            if self.supports_chunked_encoding:
+                headers['Transfer-Encoding'] = 'chunked'
+                upload_func_kwargs['chunked'] = True
+            else:
+                # Chunked transfer encoding is not supported. Need to buffer all
+                # the data in memory so we can determine file size.
+                iterator = utils.read_in_chunks(iterator=iterator)
+                data = utils.exhaust_iterator(iterator=iterator)
+
+                file_size = len(data)
+                upload_func_kwargs['data'] = data
         else:
             file_size = os.path.getsize(file_path)
-            headers['Content-Length'] = file_size
             upload_func_kwargs['chunked'] = False
 
+        if file_size:
+            headers['Content-Length'] = file_size
+
         headers['Content-Type'] = content_type
         response = self.connection.request(request_path,
                                            method=request_method, data=None,