Browse code

Reorder metadata handling in S3.object_put()

Now we set the mime-type, reduced redundancy and other
attributes also for multipart upload files.

Michal Ludvig authored on 2012/01/05 21:45:11
Showing 1 changed files
... ...
@@ -353,16 +353,7 @@ class S3(object):
353 353
         if extra_headers:
354 354
             headers.update(extra_headers)
355 355
 
356
-        multipart = False
357
-        if self.config.enable_multipart:
358
-            if size > self.config.multipart_chunk_size_mb * 1024 * 1024:
359
-                multipart = True
360
-
361
-        if multipart:
362
-            # Multipart requests are quite different... drop here
363
-            return self.send_file_multipart(file, headers, uri, size)
364
-
365
-        headers["content-length"] = size
356
+        ## MIME-type handling
366 357
         content_type = self.config.mime_type
367 358
         if not content_type and self.config.guess_mime_type:
368 359
             content_type = mime_magic(filename)
... ...
@@ -370,10 +361,24 @@ class S3(object):
370 370
             content_type = self.config.default_mime_type
371 371
         debug("Content-Type set to '%s'" % content_type)
372 372
         headers["content-type"] = content_type
373
+
374
+        ## Other Amazon S3 attributes
373 375
         if self.config.acl_public:
374 376
             headers["x-amz-acl"] = "public-read"
375 377
         if self.config.reduced_redundancy:
376 378
             headers["x-amz-storage-class"] = "REDUCED_REDUNDANCY"
379
+
380
+        ## Multipart decision
381
+        multipart = False
382
+        if self.config.enable_multipart:
383
+            if size > self.config.multipart_chunk_size_mb * 1024 * 1024:
384
+                multipart = True
385
+        if multipart:
386
+            # Multipart requests are quite different... drop here
387
+            return self.send_file_multipart(file, headers, uri, size)
388
+
389
+        ## Not multipart...
390
+        headers["content-length"] = size
377 391
         request = self.create_request("OBJECT_PUT", uri = uri, headers = headers)
378 392
         labels = { 'source' : unicodise(filename), 'destination' : unicodise(uri.uri()), 'extra' : extra_label }
379 393
         response = self.send_file(request, file, labels)