Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

GoogleCloud: Add GS_BLOB_CHUNK_SIZE setting #757

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions docs/backends/gcloud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#cache-control>`_
Expand Down
4 changes: 3 additions & 1 deletion storages/backends/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down