how to check if the file is empty or not in google cloud storage using python code in google cloud function

Viewed 835

Can someone please tell me how to check if a file in google cloud storage is empty or not using python in google cloud function. I have a requirement to check if the file is not empty, create another zero byte ".done" file for the target system for their processing and if the file is empty, do not create ".done" file which tells target system that they should not be processing the file.

1 Answers

You can use the size feature on the blob object.

Here, I list the size of the object

    from google.cloud import storage

    client = storage.Client()
    bucket = client.get_bucket('myBucket')
    blobs = bucket.list_blobs()
    for blob in blobs:
        print(blob.name)
        print(blob.size)
Related