From 34be398d1c1ff8a5fa3be1c0000aca7dc2583d73 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Mon, 9 Sep 2019 23:19:05 -0700 Subject: [PATCH] Revert "Fix for file-like objects without names (#368)" This reverts commit c73680e7d7f906b841f77dd1aa4f5c3cfa8fb3a2. --- storages/backends/s3boto3.py | 12 ------------ tests/test_s3boto3.py | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/storages/backends/s3boto3.py b/storages/backends/s3boto3.py index 2ccba09cb..52821550a 100644 --- a/storages/backends/s3boto3.py +++ b/storages/backends/s3boto3.py @@ -488,18 +488,6 @@ def _save(self, name, content): if self.preload_metadata: self._entries[encoded_name] = obj - # If both `name` and `content.name` are empty or None, your request - # can be rejected with `XAmzContentSHA256Mismatch` error, because in - # `django.core.files.storage.Storage.save` method your file-like object - # will be wrapped in `django.core.files.File` if no `chunks` method - # provided. `File.__bool__` method is Django-specific and depends on - # file name, for this reason`botocore.handlers.calculate_md5` can fail - # even if wrapped file-like object exists. To avoid Django-specific - # logic, pass internal file-like object if `content` is `File` - # class instance. - if isinstance(content, File): - content = content.file - self._save_content(obj, content, parameters=parameters) # Note: In boto3, after a put, last_modified is automatically reloaded # the next time it is accessed; no need to specifically reload it. diff --git a/tests/test_s3boto3.py b/tests/test_s3boto3.py index a4489fcfa..3d14affc5 100644 --- a/tests/test_s3boto3.py +++ b/tests/test_s3boto3.py @@ -116,7 +116,7 @@ def test_storage_save(self): obj = self.storage.bucket.Object.return_value obj.upload_fileobj.assert_called_with( - content.file, + content, ExtraArgs={ 'ContentType': 'text/plain', 'ACL': self.storage.default_acl, @@ -170,7 +170,7 @@ def test_storage_save_gzipped(self): self.storage.save(name, content) obj = self.storage.bucket.Object.return_value obj.upload_fileobj.assert_called_with( - content.file, + content, ExtraArgs={ 'ContentType': 'application/octet-stream', 'ContentEncoding': 'gzip',