GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Storage: Capture relevant headers to blob properties during download · Issue #24 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Storage: Capture relevant headers to blob properties during download #24

Copy link
Copy link
Closed
#204
Closed
Storage: Capture relevant headers to blob properties during download#24
#204
Copy link
Assignees
yoshi-automation
Labels
api: storageIssues related to the googleapis/python-storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@tseaver
tseaver
opened on Nov 13, 2019
Issue body actions

Residual from googleapis/google-cloud-python#9003.

@william-silversmith notes that even with raw_download enabled, he is unable to detect the content_type of a downloaded blob without performing an additional reload request, which is prohibitive for his usecase at scale. E.g.:

blob = bucket.blob( key )
binary = blob.download_as_string(raw_download=True)
if blob.content_encoding == 'gzip':
    return gunzip(binary)
elif blob.content_encoding == 'br':
    return brotli.decompress(binary)
else:
    return binary

Potentially even...

if blob.content_type == 'application/json':
    return json.loads(binary.decode('utf8'))
Reacted by William Silversmith

Activity

  1. william-silversmith commented on Nov 13, 2019

    @william-silversmith
    william-silversmith
    on Nov 13, 2019
    Contributor
    More actions

    Thank you Tres!

  2. tseaver commented on Nov 13, 2019

    @tseaver
    tseaver
    on Nov 13, 2019
    ContributorAuthor
    More actions

    @william-silversmith The headers needed to do this task are buried several layers deep. I'm wondering if a better solution than trying to guess which ones to map onto the blob's properties, we might be better off designing for your usecase by supplying a response_callback argument to the Blob.download_* methods:

    • The callback would take the blob instance and a requests.Response object as its arguments.
    • For non-chunked downloads, the callback would be called once; chunked downloads would call it once per chunk.

    An example callback implementation for your usecase might be something like:

    def _update_blob_content_encoding(blob, response):
        if blob.content_encoding is None:  # latch
            blob.content_encoding = response.headers.get('Content-Encoding')
  3. tseaver commented on Nov 13, 2019

    @tseaver
    tseaver
    on Nov 13, 2019
    ContributorAuthor
    More actions

    If we don't use a callback, then the relevant headers to start with would seem to be:

    • Cache-Control -> Blob.cache_control
    • Content-Disposition -> Blob.content_disposition
    • Content-Encoding -> Blob.content_encoding
    • Content-Length -> Blob.size
    • Content-Type -> Blob.content_type
    • Etag -> Blob.etag
    • X-Goog-Generation: Blob.generation
    • X-Goog-Hash: Blob.crc32c
    • X-Goog-Metageneration: Blob.metageneration
    • X-Goog-Storage-Class: Blob.storage_class
  4. william-silversmith commented on Nov 14, 2019

    @william-silversmith
    william-silversmith
    on Nov 14, 2019
    Contributor
    More actions

    I almost never need more exotic headers than the ones you listed. If it's easier to only expose those headers, that's fine with me. If you want to go for a more general solution, I am fine with a (synchronous) callback. Thanks again!

  5. william-silversmith commented on Jan 27, 2020

    @william-silversmith
    william-silversmith
    on Jan 27, 2020
    Contributor
    More actions

    Any word on when this might drop? Thanks for your help!

  6. crwilcox
    transferred this issue fromgoogleapis/google-cloud-pythonon Jan 31, 2020
  7. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Jan 31, 2020
  8. yoshi-automation
    added
    🚨This issue needs some love.
    triage meI really want to be triaged.
    on Feb 3, 2020
  9. frankyn
    added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    and removed
    🚨This issue needs some love.
    triage meI really want to be triaged.
    on Feb 4, 2020
  10. william-silversmith commented on Jul 14, 2020

    @william-silversmith
    william-silversmith
    on Jul 14, 2020
    Contributor
    More actions

    Hi Tres, I've made some changes to my own branch of this repo and they seem to work. I tried making a PR but the button was greyed out. Here's a link to the changes in case y'all are interested. In the mean time, I'll direct my repos to use the forked version.

    master...seung-lab:master

  11. william-silversmith commented on Jul 15, 2020

    @william-silversmith
    william-silversmith
    on Jul 15, 2020
    Contributor
    More actions

    Unfortunately, it seems PyPI won't let me use a direct reference to github. It would be extremely convenient if some version of this could get merged.

  12. william-silversmith commented on Jul 15, 2020

    @william-silversmith
    william-silversmith
    on Jul 15, 2020
    Contributor
    More actions

    Figured out the PR submission issue.

  13. gcf-merge-on-green
    closed this as completedin #204on Jul 23, 2020
  14. gcf-merge-on-green
    added a commit that references this issue on Jul 23, 2020

    feat(blob.py): auto-populate standard headers for non-chunked downloa…

    This issue will close once commit d8432cd is merged into the 'main' branch.
    d8432cd
  15. JustinBeckwith
    assigned
    yoshi-automation
    on Feb 1, 2021
  16. cojenco
    added 2 commits that reference this issue on Oct 13, 2021

    feat(blob.py): auto-populate standard headers for non-chunked downloa…

    This issue will close once commit 11655fe is merged into the 'main' branch.
    11655fe

    feat(blob.py): auto-populate standard headers for non-chunked downloa…

    This issue will close once commit 9f651f7 is merged into the 'main' branch.
    9f651f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @yoshi-automation
    yoshi-automation

Labels

api: storageIssues related to the googleapis/python-storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.