You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2018/03/30 05:07:22 UTC

[1/2] libcloud git commit: guess s3 multipart upload content type.

Repository: libcloud
Updated Branches:
  refs/heads/trunk f95203052 -> 9ffc89c6d


guess s3 multipart upload content type.

Signed-off-by: Quentin Pradet <qu...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/100f45fa
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/100f45fa
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/100f45fa

Branch: refs/heads/trunk
Commit: 100f45fa53bd1a048b470bf4a1823afe12539c61
Parents: f952030
Author: Iuri de Silvio <iu...@gmail.com>
Authored: Mon Nov 6 15:53:21 2017 -0200
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 30 09:06:47 2018 +0400

----------------------------------------------------------------------
 libcloud/storage/drivers/s3.py   |  4 ++++
 libcloud/test/storage/test_s3.py | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/100f45fa/libcloud/storage/drivers/s3.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/s3.py b/libcloud/storage/drivers/s3.py
index e4d48a4..6b94157 100644
--- a/libcloud/storage/drivers/s3.py
+++ b/libcloud/storage/drivers/s3.py
@@ -869,6 +869,10 @@ class BaseS3StorageDriver(StorageDriver):
         meta_data = extra.get('meta_data', None)
         acl = extra.get('acl', None)
 
+        if not content_type:
+            content_type, _ = libcloud.utils.files.guess_file_mime_type(
+                object_name)
+
         if content_type:
             headers['Content-Type'] = content_type
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/100f45fa/libcloud/test/storage/test_s3.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_s3.py b/libcloud/test/storage/test_s3.py
index 984b8ad..2b0a5da 100644
--- a/libcloud/test/storage/test_s3.py
+++ b/libcloud/test/storage/test_s3.py
@@ -21,8 +21,10 @@ import sys
 from io import BytesIO
 from hashlib import sha1
 
+import mock
 from mock import Mock
 from mock import PropertyMock
+import libcloud.utils.files
 
 from libcloud.utils.py3 import ET
 from libcloud.utils.py3 import httplib
@@ -905,6 +907,25 @@ class S3Tests(unittest.TestCase):
         self.assertEqual(obj.name, object_name)
         self.assertEqual(obj.size, CHUNK_SIZE * 3)
 
+    def test_upload_object_via_stream_guess_file_mime_type(self):
+        if self.driver.supports_s3_multipart_upload:
+            self.mock_response_klass.type = 'MULTIPART'
+        else:
+            self.mock_response_klass.type = None
+
+        container = Container(name='foo_bar_container', extra={},
+                              driver=self.driver)
+        object_name = 'foo_test_stream_data'
+        iterator = BytesIO(b('234'))
+
+        with mock.patch('libcloud.utils.files.guess_file_mime_type', autospec=True) as mock_guess_file_mime_type:
+            mock_guess_file_mime_type.return_value = ('application/zip', None)
+
+            self.driver.upload_object_via_stream(container=container,
+                                                 object_name=object_name,
+                                                 iterator=iterator)
+            mock_guess_file_mime_type.assert_called_with(object_name)
+
     def test_upload_object_via_stream_abort(self):
         if not self.driver.supports_s3_multipart_upload:
             return


[2/2] libcloud git commit: Add changes for #1195

Posted by qu...@apache.org.
Add changes for #1195

Closes #1195


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/9ffc89c6
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9ffc89c6
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9ffc89c6

Branch: refs/heads/trunk
Commit: 9ffc89c6d31f1022f8310b80a0288078a32d34d3
Parents: 100f45f
Author: Quentin Pradet <qu...@apache.org>
Authored: Fri Mar 30 09:05:55 2018 +0400
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 30 09:06:53 2018 +0400

----------------------------------------------------------------------
 CHANGES.rst | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9ffc89c6/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index c98b208..90554f6 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -57,6 +57,9 @@ Storage
 - [Azure Blob storage] Allow filtering lists by prefix (LIBCLOUD-986, GITHUB-1193)
   [Joshua Hawkinson]
 
+- [S3] Guess s3 upload content type (LIBCLOUD-958, GITHUB-1195)
+  [Iuri de Silvio]
+
 Changes in Apache Libcloud 2.3.0
 --------------------------------