Skip to content

Commit

Permalink
Add support for files > 5 gb with S3BotoStorage (#201)
Browse files Browse the repository at this point in the history
* Add support for files > 5 gb with S3BotoStorage

Fixes #194

* Fix tests
  • Loading branch information
btoueg authored and jschneier committed Sep 13, 2016
1 parent 5f28057 commit b334a99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def _save_content(self, obj, content, parameters):
if self.default_acl:
put_parameters['ACL'] = self.default_acl
content.seek(0, os.SEEK_SET)
obj.put(Body=content, **put_parameters)
obj.upload_fileobj(content, ExtraArgs=put_parameters)

def delete(self, name):
name = self._normalize_name(self._clean_name(name))
Expand Down
27 changes: 16 additions & 11 deletions tests/test_s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ def test_storage_save(self):
self.storage.bucket.Object.assert_called_once_with(name)

obj = self.storage.bucket.Object.return_value
obj.put.assert_called_with(
Body=content,
ContentType='text/plain',
ACL=self.storage.default_acl,
obj.upload_fileobj.assert_called_with(
content,
ExtraArgs={
'ContentType': 'text/plain',
'ACL': self.storage.default_acl,
}
)

def test_storage_save_gzip(self):
Expand All @@ -133,14 +135,17 @@ def test_storage_save_gzip(self):
content = ContentFile("I should be gzip'd")
self.storage.save(name, content)
obj = self.storage.bucket.Object.return_value
obj.put.assert_called_with(
Body=mock.ANY,
ContentType='text/css',
ContentEncoding='gzip',
ACL=self.storage.default_acl
obj.upload_fileobj.assert_called_with(
mock.ANY,
ExtraArgs={
'ContentType': 'text/css',
'ContentEncoding': 'gzip',
'ACL': self.storage.default_acl,
}
)
body = obj.put.call_args[1]['Body']
zfile = gzip.GzipFile(mode='rb', fileobj=body)
args, kwargs = obj.upload_fileobj.call_args
content = args[0]
zfile = gzip.GzipFile(mode='rb', fileobj=content)
self.assertEquals(zfile.read(), b"I should be gzip'd")

def test_compress_content_len(self):
Expand Down

0 comments on commit b334a99

Please sign in to comment.