Skip to content

Commit

Permalink
Fix URI -> blob name conversion in 'Client download_blob_to_file'. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
HemangChothani authored and tseaver committed Jun 26, 2019
1 parent 021e3fb commit a9d9cca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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
17 changes: 17 additions & 0 deletions storage/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,23 @@ 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
)

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

0 comments on commit a9d9cca

Please sign in to comment.