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 — Batch uploading of files · Issue #3139 · googleapis/google-cloud-python

Batch uploading of files #3139

New issue
Copy link
New issue
Copy link
Closed
Closed
Batch uploading of files#3139
Copy link
Assignees
tseaver
Labels
api: storageIssues related to the Cloud Storage API.

Description

@tartavull
tartavull
opened on Mar 14, 2017
Issue body actions

I'm confused about this comment https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/storage/google/cloud/storage/blob.py#L589

What is the correct way of uploading blobs in a batch?

    client = storage.Client.from_service_account_json('client-secret.json', project=PROJECT_NAME)
    bucket = client.get_bucket(BUCKET_NAME)
    with client.batch():
        for i in range(10):
            with open('base.py', 'rb') as my_file:
                blob = storage.Blob('/test/{}'.format(i), bucket)
                blob.upload_from_file(my_file, client=client)

This, of course, won't work because is using client._base_connection instead of client.current_batch.

Reacted by Gábor Fehér

Activity

  1. tseaver
    added
    api: storageIssues related to the Cloud Storage API.
    on Mar 14, 2017
  2. tseaver commented on Mar 14, 2017

    @tseaver
    tseaver
    on Mar 14, 2017
    Contributor
    More actions

    @tartavull Thanks for the report! Unfortunately, the back-end API doesn't support batching "media" operations, which means we don't support it either.

    Examples of situations when you might want to use batching:
    
    - Updating metadata, such as permissions, on many objects.
    - Deleting many objects.
    ...
    
    * Note: Currently, Google Cloud Storage does not support batch operations for media,
      either for upload or download.
    
  3. tseaver
    closed this as completedon Mar 14, 2017
  4. arvindnrbt commented on Jul 17, 2018

    @arvindnrbt
    arvindnrbt
    on Jul 17, 2018
    More actions

    Any update on this? How do we upload thousands of files to GCS ? Should we always iterate and use file upload?

  5. tseaver commented on Jul 24, 2018

    @tseaver
    tseaver
    on Jul 24, 2018
    Contributor
    More actions

    @arvindnrbt with consulting hat on "It depends...". You could:

    • Iterate and upload files one by one.
    • Populate a queue.Queue with the filenames and have worker threads upload items from the queue.
    • Populate a cross-process queue and have worker processes upload items from the queue.

    You can't:

    • Upload a zipfile and have GCS automagically explode its entries into blobs / objects.
    • Create a "batched" MIME request and do multiple uploads in a single request.
    Reacted by Arvind Natarajan and Sonny MH
    Reacted by David Bernat, Harvey Xia, limbuu, alexandervlpl, Theo Linnemann, stevenleeg, valdebrutal, Mykola Morozov and C Mo
  6. limbuu commented on Jul 25, 2019

    @limbuu
    limbuu
    on Jul 25, 2019
    More actions

    any update on this? @tseaver

  7. tseaver commented on Jul 25, 2019

    @tseaver
    tseaver
    on Jul 25, 2019
    Contributor
    More actions

    @limbuu I'm not sure what you're asking: the Storage API supports batch requests only for object metadata, not for uploads / downloads:

    Note: Cloud Storage does not support batch operations for media, either for upload or download.

    which means we can't support it in the google-cloud-storage client library, either.

    The other solutions I outlined above aren't suitable for the library: they are application-dependent.

  8. xucian commented on May 25, 2020

    @xucian
    xucian
    on May 25, 2020
    More actions

    For anyone that might want to batch upload/download.
    I wanted to speed up this process and it turned out that spawning a few threads and using a different google storage client instance in each did improve the speed significantly. Tested on a 6-core machine. I just needed to partition the list of files to upload/download myself.
    Hope this will be helpful for some.

    Reacted by Sonny MH, Ruslan Baratov, Ivan Protsyuk, Toni Anev, nkmry and Dom
    Reacted by Alan Ko
  9. JustinBeckwith
    assigned
    tseaver
    on Feb 1, 2021
  10. zdhernandez commented on Jan 2, 2022

    @zdhernandez
    zdhernandez
    on Jan 2, 2022
    More actions

    @JustinBeckwith Has this been improved? Why can't the client, behind the scenes, do what @TFGStudios did?

    Reacted by xucian, Luis Zugasti, Toni Anev, nkmry, Alexey Sergeev and Yash Jha
  11. gcf-merge-on-green
    added a commit that references this issue on Oct 5, 2023

    build(deps): bump urllib3 from 1.26.12 to 1.26.17 in /.kokoro (#11783)

    e476c6c
  12. parthea
    added a commit that references this issue on Mar 9, 2026

    build(deps): bump urllib3 from 1.26.12 to 1.26.18 in /.kokoro (#322)

    87baa13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

Labels

api: storageIssues related to the Cloud Storage API.

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.