Skip to content

Allow passing files not at beginning to 'ResumableUpload' #165

@retnikt

Description

@retnikt

Environment details

Ubuntu, Python 3.7, Google Cloud Storage 1.23.0

Steps to reproduce

  1. Create a Blob
  2. Use blob.upload_from_file(fp) where fp is not at the beginning of the stream (i.e. it has been sought)

Code example

from google.cloud import storage
client = storage.Client()
bucket = client.bucket("somebucket")
blob = bucket.blob("path/to/blob.txt")
fp = io.BytesIO(b'\0' * 100)
fp.seek(40)
blob.upload_from_file(fp)

Traceback

Traceback (most recent call last):
  ...
  File "/.../google/cloud/storage/blob.py", line 1262, in upload_from_file
    created_json = self._do_upload(
  File "/.../google/cloud/storage/blob.py", line 1172, in _do_upload
    response = self._do_resumable_upload(
  File ".../google/cloud/storage/blob.py", line 1110, in _do_resumable_upload
    upload, transport = self._initiate_resumable_upload(
  File "/.../google/cloud/storage/blob.py", line 1059, in _initiate_resumable_upload
    upload.initiate(
  File "/.../google/resumable_media/requests/upload.py", line 338, in initiate
    method, url, payload, headers = self._prepare_initiate_request(
  File "/.../google/resumable_media/_upload.py", line 415, in _prepare_initiate_request
    raise ValueError(u"Stream must be at beginning.")
ValueError: Stream must be at beginning.

Description

I cannot see any reason why there is the check if stream.tell() != 0. It seems to serve only to frustrate users trying to upload from custom unseekable file-like objects (e.g. googleapis/google-cloud-python#7282), or only parts of files. Can this not be removed, or moved to somewhere else more relevant in the codebase if it serves a purpose only thence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: storageIssues related to the googleapis/google-resumable-media-python 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