diff --git a/storage/google/cloud/storage/client.py b/storage/google/cloud/storage/client.py index 7452d7adcd2b..14643e27b3c8 100644 --- a/storage/google/cloud/storage/client.py +++ b/storage/google/cloud/storage/client.py @@ -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) diff --git a/storage/tests/system.py b/storage/tests/system.py index 0b9127d7afdb..6aa68aee0628 100644 --- a/storage/tests/system.py +++ b/storage/tests/system.py @@ -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.")