Skip to content
Browse files

Reorder metadata handling in S3.object_put()

Now we set the mime-type, reduced redundancy and other
attributes also for multipart upload files.
  • Loading branch information...
1 parent b78cd50 commit 57da4c64b24e3cb6ccac5000beec6fa7c4e9a208 @mludvig mludvig committed Jan 6, 2012
Showing with 15 additions and 10 deletions.
  1. +15 −10 S3/S3.py
View
25 S3/S3.py
@@ -353,27 +353,32 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
if extra_headers:
headers.update(extra_headers)
- multipart = False
- if self.config.enable_multipart:
- if size > self.config.multipart_chunk_size_mb * 1024 * 1024:
- multipart = True
-
- if multipart:
- # Multipart requests are quite different... drop here
- return self.send_file_multipart(file, headers, uri, size)
-
- headers["content-length"] = size
+ ## MIME-type handling
content_type = self.config.mime_type
if not content_type and self.config.guess_mime_type:
content_type = mime_magic(filename)
if not content_type:
content_type = self.config.default_mime_type
debug("Content-Type set to '%s'" % content_type)
headers["content-type"] = content_type
+
+ ## Other Amazon S3 attributes
if self.config.acl_public:
headers["x-amz-acl"] = "public-read"
if self.config.reduced_redundancy:
headers["x-amz-storage-class"] = "REDUCED_REDUNDANCY"
+
+ ## Multipart decision
+ multipart = False
+ if self.config.enable_multipart:
+ if size > self.config.multipart_chunk_size_mb * 1024 * 1024:
+ multipart = True
+ if multipart:
+ # Multipart requests are quite different... drop here
+ return self.send_file_multipart(file, headers, uri, size)
+
+ ## Not multipart...
+ headers["content-length"] = size
request = self.create_request("OBJECT_PUT", uri = uri, headers = headers)
labels = { 'source' : unicodise(filename), 'destination' : unicodise(uri.uri()), 'extra' : extra_label }
response = self.send_file(request, file, labels)

0 comments on commit 57da4c6

Please sign in to comment.
Something went wrong with that request. Please try again.