0

Hi I wondering whether it was possible to check whether a file exists on firebase storage using python. Here are a couple ways of doing it for other languages.

How to check if a file exists in Firebase storage from your android application?

how to check if file exists in Firebase Storage?

What is the equivalent method for python.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
GILO
  • 2,444
  • 21
  • 47

1 Answers1

2

I was able to get it to work using the request module and using the public url for the file. Hope this helps anyone else facing the same issue.

import requests
from firebase_admin import storage


#Creates the blob reference to file on the server
bucket = storage.bucket()
blob = bucket.blob("firebase/path/to/file")

#Requests the file using the public url
r = requests.head(blob.public_url)
            
#Whether the file exists or not on the server
fileExists = (r.status_code == requests.codes.ok)

Edit

Thanks to some helpful pointers you can use

fileExists = blob.exists()

Which means you no longer require the requests module

GILO
  • 2,444
  • 21
  • 47