Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download all files from firebase storage using python

I am working on a project where the user uploads images into firebase storage and i want to retrieve all those images and store locally.

Using pyrebase i can manage to download a single image(if i know the filename or download URL)

storage = firebase.storage()
storage.child("images/example.jpg").download("img")

But in my situation i may not know what is the name or download URL of file is. Pyrebase only supports to download single file and the filename should also be known.

Is there an alternative way to list / download all the files from firebase storage? Code snippet would be helpful.

like image 555
saify Avatar asked Aug 22 '26 00:08

saify


1 Answers

Here the file names are in 1,2,3,.... format. Here you have to add the json account also, by downloading it from firebase settings.

config={
    "serviceAccount":"abc.json"
}

firebase=pyrebase.initialize_app(config)
storage = firebase.storage()

ab=str(1)    
all_files = storage.child("images").list_files() //Enter the name of the folder    
for file in all_files:            
try:
        print(file.name)    
        z=storage.child(file.name).get_url(None)    
        storage.child(file.name).download(""+path+"/"+ab+".mp3")    
        x=int(ab)     
        ab=str(x+1)    
except:    
        print('Download Failed')    
like image 108
Pavani Jayalath Avatar answered Aug 23 '26 15:08

Pavani Jayalath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!