Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge jschneier#450.
Browse files Browse the repository at this point in the history
  • Loading branch information
gomlgs committed Mar 16, 2018
1 parent d2bf808 commit e073148
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class S3Boto3StorageFile(File):
buffer_size = setting('AWS_S3_FILE_BUFFER_SIZE', 5242880)

def __init__(self, name, mode, storage, buffer_size=None):
if 'r' in mode and 'w' in mode:
raise ValueError("Can't combine 'r' and 'w' in mode.")
self._storage = storage
self.name = name[len(self._storage.location):].lstrip('/')
self._mode = mode
Expand Down Expand Up @@ -91,7 +93,7 @@ def _get_file(self):
)
if 'r' in self._mode:
self._is_dirty = False
self._file.write(self.obj.get()['Body'].read())
self.obj.download_fileobj(self._file)
self._file.seek(0)
if self._storage.gzip and self.obj.content_encoding == 'gzip':
self._file = GzipFile(mode=self._mode, fileobj=self._file, mtime=0.0)
Expand Down Expand Up @@ -141,7 +143,9 @@ def _flush_write_buffer(self):
self._write_counter += 1
self.file.seek(0)
part = self._multipart.Part(self._write_counter)
part.upload(Body=self.file.read())
part.upload(Body=self.file)
self.file.seek(0)
self.file.truncate()

def close(self):
if self._is_dirty:
Expand Down

0 comments on commit e073148

Please sign in to comment.