SamGhatak
SamGhatak

Reputation: 1493

Unable to download files from firebase through pyrebase

I am stuck with it for a long time now, must be something silly!!!

I have this simple code that uses pyrebase to connect to Firebase:

db = firebase.database()
auth = firebase.auth()
storage = firebase.storage()
user = auth.sign_in_with_email_and_password('user','pwd')

tok = user['idToken']

try:
    files = db.child("files").get(tok)
    l = []
    for f in files.each():
        l = f.val()
        print(l)
        storage.child(l).download(l,token=tok)
        # url = storage.child(l).get_url(tok)  -----This line gets the proper URL
except Exception as e:
    print(e)

I am getting data correctly accessed from DB, but the download task does nothing. I have no idea what I am doing wrong here.

Thanks in advance!

EDIT 1: as per suggestion:

Database structure:

{
  "files" : {
    "-L2vvsSL3l95QZqMILRb" : "car_WIFI_6cf4d4f1-4bfe-488b-b671-d0f816cd5e65.txt",
    "-L2vvsSScNqiUZ-HYTM1" : "car_GPS_6cf4d4f1-4bfe-488b-b671-d0f816cd5e65.txt"
  }
}

And storage structure:

Data Storage Screenshot

Upvotes: 1

Views: 3012

Answers (1)

Rosário P. Fernandes
Rosário P. Fernandes

Reputation: 11326

According to this issue on Pyrebase's GitHub, you need to add a service account credential in order to download storage files. That allows Pyrebase to authenticate with Firebase as an admin and disregard any security rules.

Upvotes: 1

Related Questions