Fixed -- Stream large file reads from S3
@@ -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
@@ -93,7 +95,7 @@ class S3Boto3StorageFile(File):
)
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)
