Read blob from google bucket knowing the name of the file

26 Views Asked by At

I’m trying to read an excel file in Google bucket by using its name to find it. I have below code to find the latest file in the bucket (file that was added last):

bucket_name = 'bucket_name'
blobs = [(blob, blob.updated) for blob in client.list_blobs(bucket_name, prefix ='')]
latest = sorted(blobs, key=lambda tup: tup[1])[-1][0]
latest = latest.name.split('/')
file_name = ''.join(latest)
print(file_name)

Then I’m trying to download_as_bytes. However, I can’t do that since file_name is not a blob. Is there any way to find the latest added blob in the google bucket and read so that I could then download_as_bytes? Or is there a way to somehow pass the file_name to find the blob information so that I could download_as_bytes?

0

There are 0 best solutions below