Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: fix Client download_blob_to_file fails #8440

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion storage/google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def download_blob_to_file(self, blob_or_uri, file_obj, start=None, end=None):
if scheme != "gs":
raise ValueError("URI scheme must be gs")
bucket = Bucket(self, name=netloc)
blob_or_uri = Blob(path, bucket)
blob_or_uri = Blob(path[1:], bucket)

blob_or_uri.download_to_file(file_obj, client=self, start=start, end=end)

Expand Down
15 changes: 15 additions & 0 deletions storage/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,21 @@ def test_copy_existing_file(self):
copied_contents = new_blob.download_as_string()
self.assertEqual(base_contents, copied_contents)

def test_download_blob_w_uri(self):
blob = self.bucket.blob("MyBuffer")
file_contents = b"Hello World"
blob.upload_from_string(file_contents)
self.case_blobs_to_delete.append(blob)

temp_filename = tempfile.mktemp()
with open(temp_filename, "wb") as file_obj:
Config.CLIENT.download_blob_to_file('gs://'+self.bucket.name+'/MyBuffer', file_obj)
tseaver marked this conversation as resolved.
Show resolved Hide resolved

with open(temp_filename, "rb") as file_obj:
stored_contents = file_obj.read()

self.assertEqual(file_contents, stored_contents)


class TestUnicode(unittest.TestCase):
@unittest.skipIf(RUNNING_IN_VPCSC, "Test is not VPCSC compatible.")
Expand Down