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 — Blob.upload_from_file doesn't work for file-like objects without size parameter · Issue #900 · googleapis/google-cloud-python

Blob.upload_from_file doesn't work for file-like objects without size parameter #900

New issue
Copy link
New issue
Copy link
Closed
Closed
Blob.upload_from_file doesn't work for file-like objects without size parameter#900
Copy link
Assignees
dhermes
Labels
api: storageIssues related to the Cloud Storage API.
Milestone
Storage Stable

Description

@theacodes
theacodes
opened on May 28, 2015
Issue body actions

When using StringIO, io.BytesIO or other file-like objects (such as Flask/werkzeug's file upload object), trying to upload via Blob.upload_from_file doesn't work because it attempts to find the size of the object using os.stat throwing a AttributeError: StringIO instance has no attribute 'fileno'. Passing in the size manually fixes this, but imo this inconsistency shouldn't burden the user as there are other ways than fileno to determine the size of a StringIO or io.BytesIO instance (seek, tell).

At any rate, the error message could be more helpful.

Activity

  1. dhermes commented on May 29, 2015

    @dhermes
    dhermes
    on May 29, 2015
    Contributor
    More actions

    Can you give a stacktrace of the error message?

    The offending line is

            # Get the basic stats about the file.
            total_bytes = size or os.fstat(file_obj.fileno()).st_size

    which as @jonparrott points out, assumes the file-like object is a file (from the stdlib).

  2. theacodes commented on May 29, 2015

    @theacodes
    theacodes
    on May 29, 2015
    ContributorAuthor
    More actions
    Traceback (most recent call last):
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
        return self.wsgi_app(environ, start_response)
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
        response = self.make_response(self.handle_exception(e))
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
        response = self.full_dispatch_request()
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
        rv = self.dispatch_request()
      File "/Users/jonwayne/workspace/getting-started-python/env/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "/Users/jonwayne/workspace/getting-started-python/oauth2/__init__.py", line 33, in decr
        return f(*args, **kwargs)
      File "/Users/jonwayne/workspace/getting-started-python/bookshelf/crud.py", line 57, in add
        image_url = upload_image_file(request.files.get('image'))
      File "/Users/jonwayne/workspace/getting-started-python/bookshelf/crud.py", line 25, in upload_image_file
        current_app.config['ALLOWED_EXTENSIONS']
      File "/Users/jonwayne/workspace/getting-started-python/storage/__init__.py", line 52, in upload_file
        blob.upload_from_file(file)
      File "/Users/jonwayne/workspace/getting-started-python/env/src/gcloud/gcloud/storage/blob.py", line 395, in upload_from_file
        total_bytes = size or os.fstat(file_obj.fileno()).st_size
    UnsupportedOperation: fileno
    
  3. dhermes commented on May 30, 2015

    @dhermes
    dhermes
    on May 30, 2015
    Contributor
    More actions

    Ha, ok. Doesn't provide anything we didn't know.

  4. theacodes commented on May 30, 2015

    @theacodes
    theacodes
    on May 30, 2015
    ContributorAuthor
    More actions

    Heh, let me know if there's anything else I can provide to help here. The file-like object is a flask file upload (werkzeug.FileStorage). It fails likewise when using blob.upload_from_file(file) and blob.upload_from_file(file.stream).

  5. dhermes
    added
    api: storageIssues related to the Cloud Storage API.
    on Jun 5, 2015
  6. dhermes
    modified the milestone: Storage Stable on Jun 5, 2015
  7. dhermes
    self-assigned this
    on Jun 6, 2015
  8. dhermes
    added a commit that references this issue on Jun 6, 2015

    Makes checking fstat for file optional.

    This issue will close once commit 8358af2 is merged into the 'master' branch.
    8358af2
  9. dhermes
    closed this as completedin #914on Jun 18, 2015
  10. theacodes
    unassigned
    dhermes
    on Sep 28, 2018
  11. JustinBeckwith
    assigned
    dhermes
    on Feb 1, 2021
  12. gcf-owl-bot
    added a commit that references this issue on May 7, 2024

    feat: Update Compute Engine API to revision 20240430 (#900)

    3c4f722
  13. parthea
    added 2 commits that reference this issue on May 11, 2024

    feat: [google-cloud-compute] Update Compute Engine API to revision 20…

    f515bc6

    chore: release main (#12671)

    6ccf5dc
  14. parthea
    added a commit that references this issue on Aug 21, 2025

    chore(deps): update all dependencies (#900)

    668a9d8
  15. parthea
    added a commit that references this issue on Sep 16, 2025

    chore(deps): update all dependencies (#900)

    ec0b3b4
  16. parthea
    added 4 commits that reference this issue on Nov 22, 2025

    chore: add experimental async data client (#920)

    07c1344

    fix: remove Python 3.7 support due to EOL (#900)

    e8ab4e3

    build(deps): [autoapprove] bump certifi from 2022.12.7 to 2023.7.22 (#…

    75470ce

    chore: update authorized_user.json and use latest sphinx (#900)

    727c751
  17. parthea
    added 3 commits that reference this issue on Mar 2, 2026

    chore: add experimental async data client (#920)

    5cd2349

    chore: Bump grpcio version to 1.51.3 (#900)

    016e664

    chore(deps): update dependency pandas to v1.3.2 (#900)

    eb3456d
  18. parthea
    added a commit that references this issue on Sep 8, 2026

    docs: migrate code from googleapis/python-bigquery (#18303)

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

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    • Storage Stable

    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.