nhorvath / Pyrebase4

A simple python wrapper for the Firebase API. ⛺

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with downloading files: File does not download and no errors

fenchai23 opened this issue · comments

I am just trying to download all files in a folder, this worked on pyrebase on my main PC but somehow pyrebase can't be installed on my work PC so I googled and had to install pyrebase4.

apart from having to change this syntax: from storage.child(file.name).download(os.path.basename(file.name)) to storage.child(file.name).download(path, os.path.basename(file.name))

I was able to run the script without issues... until I realize that none of my files are getting downloaded. Maybe my path is incorrect? this is my script:

I know that my script able to access firebase because it worked on pyrebase on my PC and this is the print I get from path and file respectively.

path: https://firebasestorage.googleapis.com/v0/b/asdasdadasdad.appspot.com/o/records%2F000000000000053-777-cotizacion.pdf?alt=media
os.path.basename(file.name): 000000000000053-777-cotizacion.pdf

import pyrebase
import os
import time

project_root = os.path.dirname(os.path.dirname(__file__))
keys_path = os.path.join(project_root, 'keys')
hylKeyPath = os.path.join(keys_path, 'ServiceAccountKey.json')


firebase = pyrebase.initialize_app({
    "apiKey": "asdadasdasddadsa",
    "authDomain": "asdadsada.firebaseapp.com",
    "databaseURL": "https://asdasdaddasda.firebaseio.com",
    "storageBucket": "asdasdadasd.appspot.com",
    "serviceAccount": asdKeyPath
})

storage = firebase.storage()


def sleepCountDown(t):
    while t > 0:
        print(f"sleeping for {t} seconds...")
        t -= 1
        time.sleep(1)


while True:
    print('fetching data')
    files = storage.child('/').list_files()

    for file in files:
        if 'records/' in file.name:
            # get the file url path
            print(storage.child(file.name).get_url(None))

            path = storage.child(file.name).get_url(None)

            print(os.path.basename(file.name))

            # downloads file
            storage.child(file.name).download(path, os.path.basename(file.name))
            # deletes file? kinda deletes the entire folder
            storage.delete(file.name)
    sleepCountDown(10)

btw thanks for forking pyrebase.

fixed by changing the path:

storage.child(file.name).download(file.name, os.path.basename(file.name))

instead of using the URL path