* S3/S3.py, S3/Config.py: Support for MIME types. Both
default and guessing. Fixes bug #1872192 (Thanks Martin Herr)
git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@157 830e0280-6d2a-0410-9c65-932aecc39d9d
... | ... |
@@ -1,3 +1,10 @@ |
1 |
+2008-02-11 Michal Ludvig <michal@logix.cz> |
|
2 |
+ |
|
3 |
+ * S3/S3.py, S3/Config.py: Support for MIME types. Both |
|
4 |
+ default and guessing. Fixes bug #1872192 (Thanks Martin Herr) |
|
5 |
+ |
|
6 |
+2007-11-13 Michal Ludvig <michal@logix.cz> |
|
7 |
+ |
|
1 | 8 |
* Released version 0.9.5 |
2 | 9 |
---------------------- |
3 | 10 |
|
... | ... |
@@ -44,6 +44,8 @@ class Config(object): |
44 | 44 |
gpg_decrypt = "%(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s" |
45 | 45 |
use_https = False |
46 | 46 |
bucket_location = "US" |
47 |
+ default_mime_type = "binary/octet-stream" |
|
48 |
+ guess_mime_type = False |
|
47 | 49 |
|
48 | 50 |
## Creating a singleton |
49 | 51 |
def __new__(self, configfile = None): |
... | ... |
@@ -11,6 +11,7 @@ import sha |
11 | 11 |
import hmac |
12 | 12 |
import httplib |
13 | 13 |
import logging |
14 |
+import mimetypes |
|
14 | 15 |
from logging import debug, info, warning, error |
15 | 16 |
from stat import ST_SIZE |
16 | 17 |
|
... | ... |
@@ -174,6 +175,13 @@ class S3(object): |
174 | 174 |
if extra_headers: |
175 | 175 |
headers.update(extra_headers) |
176 | 176 |
headers["content-length"] = size |
177 |
+ content_type = None |
|
178 |
+ if self.config.guess_mime_type: |
|
179 |
+ content_type = mimetypes.guess_type(filename)[0] |
|
180 |
+ if not content_type: |
|
181 |
+ content_type = self.config.default_mime_type |
|
182 |
+ debug("Content-Type set to '%s'" % content_type) |
|
183 |
+ headers["content-type"] = content_type |
|
177 | 184 |
if self.config.acl_public: |
178 | 185 |
headers["x-amz-acl"] = "public-read" |
179 | 186 |
request = self.create_request("OBJECT_PUT", bucket = bucket, object = object, headers = headers) |