Skip to content

Commit

Permalink
Reorder metadata handling in S3.object_put()
Browse files Browse the repository at this point in the history
Now we set the mime-type, reduced redundancy and other
attributes also for multipart upload files.
  • Loading branch information
mludvig committed Jan 5, 2012
1 parent b78cd50 commit 57da4c6
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions S3/S3.py
Expand Up @@ -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)
Expand Down

0 comments on commit 57da4c6

Please sign in to comment.