From 62379489adfb638cd4ddec0da6ded8f30361efe7 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Tue, 10 Sep 2019 01:14:38 -0700 Subject: [PATCH] GoogleCloud: Add GS_BLOB_CHUNK_SIZE setting (#757) --- docs/backends/gcloud.rst | 9 +++++++++ storages/backends/gcloud.py | 4 +++- tests/test_gcloud.py | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/backends/gcloud.rst b/docs/backends/gcloud.rst index 476fefd46..cbfc19682 100644 --- a/docs/backends/gcloud.rst +++ b/docs/backends/gcloud.rst @@ -138,6 +138,15 @@ By default files with the same name will overwrite each other. Set this to ``Fal The maximum amount of memory a returned file can take up (in bytes) before being rolled over into a temporary file on disk. Default is 0: Do not roll over. +``GS_BLOB_CHUNK_SIZE`` (optional: default is ``None``) + +The size of blob chunks that are sent via resumable upload. If this is not set then the generated request +must fit in memory. Recommended if you are going to be uploading large files. + +.. note:: + + This must be a multiple of 256K (1024 * 256) + ``GS_CACHE_CONTROL`` (optional: default is ``None``) Sets Cache-Control HTTP header for the file, more about HTTP caching can be found `here `_ diff --git a/storages/backends/gcloud.py b/storages/backends/gcloud.py index 4715326de..5b2af3e84 100644 --- a/storages/backends/gcloud.py +++ b/storages/backends/gcloud.py @@ -30,7 +30,9 @@ def __init__(self, name, mode, storage): self._storage = storage self.blob = storage.bucket.get_blob(name) if not self.blob and 'w' in mode: - self.blob = Blob(self.name, storage.bucket) + self.blob = Blob( + self.name, storage.bucket, + chunk_size=setting('GS_BLOB_CHUNK_SIZE')) self._file = None self._is_dirty = False diff --git a/tests/test_gcloud.py b/tests/test_gcloud.py index 393bacbf6..60a895108 100644 --- a/tests/test_gcloud.py +++ b/tests/test_gcloud.py @@ -86,7 +86,7 @@ def test_open_write(self, MockBlob): self.storage.default_acl = 'projectPrivate' f = self.storage.open(self.filename, 'wb') - MockBlob.assert_called_with(self.filename, self.storage._bucket) + MockBlob.assert_called_with(self.filename, self.storage._bucket, chunk_size=None) f.write(data) tmpfile = f._file