Skip to content

Storage: Cannot download brotli compressed/encoded files from cloud storage #9003

@m3o7

Description

@m3o7

Environment details

Issue caused when deployed as cloud function (with google-cloud-storage==1.15.0):

gcloud functions deploy generate_file --runtime python37 --trigger-http

Steps to reproduce

  1. generate string content
  2. compress content with brotli
  3. create new blob
  4. set blob encoding to br for brotli
  5. upload blob via upload_from_string
  6. download blob via download_as_string

Code example

https://gist.github.com/marcopashkov/9175be7c72f96ffc8ea984d892e07f98

Stack trace

textPayload: "Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 346, in run_http_function
    result = _function_handler.invoke_user_function(flask.request)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 210, in call_user_function
    return self._user_function(request_or_event)
  File "/user_code/main.py", line 26, in generate_file
    download_content = blob.download_as_string()
  File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 697, in download_as_string
    self.download_to_file(string_buffer, client=client, start=start, end=end)
  File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 636, in download_to_file
    self._do_download(transport, file_obj, download_url, headers, start, end)
  File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 574, in _do_download
    download.consume(transport)
  File "/env/local/lib/python3.7/site-packages/google/resumable_media/requests/download.py", line 174, in consume
    self._write_to_stream(result)
  File "/env/local/lib/python3.7/site-packages/google/resumable_media/requests/download.py", line 137, in _write_to_stream
    raise common.DataCorruption(response, msg)
google.resumable_media.common.DataCorruption: Checksum mismatch while downloading:

  https://www.googleapis.com/download/storage/v1/b/REDACTED.appspot.com/o/brotli_test%2F2019-08-09.html?generation=1565385647421287&alt=media

The X-Goog-Hash header indicated an MD5 checksum of:

  O0XeX+jfZFb9nQYmC6DU2Q==

but the actual MD5 checksum of the downloaded contents was:

  qawBTvkgTjJkJklqx11tRw==

" 

Metadata

Metadata

Labels

api: storageIssues related to the Cloud Storage API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions