Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed #383 -- Stream large file reads from S3 #548

Merged
merged 1 commit into from
Aug 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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 @@ -93,7 +95,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