Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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.
  • Loading branch information...
commit 57da4c64b24e3cb6ccac5000beec6fa7c4e9a208 1 parent b78cd50
Michal Ludvig mludvig authored

Showing 1 changed file with 15 additions and 10 deletions. Show diff stats Hide diff stats

  1. +15 10 S3/S3.py
25 S3/S3.py
@@ -353,16 +353,7 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
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 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
370 361 content_type = self.config.default_mime_type
371 362 debug("Content-Type set to '%s'" % content_type)
372 363 headers["content-type"] = content_type
  364 +
  365 + ## Other Amazon S3 attributes
373 366 if self.config.acl_public:
374 367 headers["x-amz-acl"] = "public-read"
375 368 if self.config.reduced_redundancy:
376 369 headers["x-amz-storage-class"] = "REDUCED_REDUNDANCY"
  370 +
  371 + ## Multipart decision
  372 + multipart = False
  373 + if self.config.enable_multipart:
  374 + if size > self.config.multipart_chunk_size_mb * 1024 * 1024:
  375 + multipart = True
  376 + if multipart:
  377 + # Multipart requests are quite different... drop here
  378 + return self.send_file_multipart(file, headers, uri, size)
  379 +
  380 + ## Not multipart...
  381 + headers["content-length"] = size
377 382 request = self.create_request("OBJECT_PUT", uri = uri, headers = headers)
378 383 labels = { 'source' : unicodise(filename), 'destination' : unicodise(uri.uri()), 'extra' : extra_label }
379 384 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.