2

I'm trying to download the image file stored in Firebase, to use it as user profile picture later. Right now I can't get past the downloading part. I named the image as the user's UID, to download the proper image for every user. I used:

storage.child("/user_info/user_image/"+user_uid+".png").download("/user files/", user_uid+".png")

to download it. It seems to me that it does nothing. I checked the file name and path. It's correct. Here's the file in the storage.

main.py

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import pyrebase

firebaseConfig = {
    your config here
}
firebase = pyrebase.initialize_app(firebaseConfig)
auth = firebase.auth()
db=firebase.database()
storage=firebase.storage()

class MainApp(MDApp):
    
    def build(self):
        return Builder.load_file('main.kv')
    
    def login(self):
        email = self.root.get_screen("test1win").ids.user_mail.text
        password = self.root.get_screen("test1win").ids.password.text
        
        try:
            login = auth.sign_in_with_email_and_password(email, password)
            self.root.current = "test2win"
            print("Login Success")
            global user_uid
            user_uid = login['localId']
            print(user_uid)
            global user_uinf
            user_uinf = []
            
        except:
            print("Invalid credentials.")
        
    def database_info(self):
        storage.child("/user_info/user_image/"+user_uid+".png").download("/user files/", user_uid+".png")
        userinf = db.child('userinfo').child(user_uid).get()
        for x in userinf.each():
            user_uinf.append(x.val())
        print(user_uinf)
        self.root.get_screen("test2win").ids.testwin2label.text = user_uinf[1]+" "+user_uinf[4]+", "+user_uinf[0]+", "+str(user_uinf[2])+", "+user_uinf[3]

class WindowManager(ScreenManager):
    pass

class TestWindow1(Screen):
    pass

class TestWindow2(Screen):
    pass

if __name__ == "__main__":
    MainApp().run()

main.kv

#: include testwindow1.kv
#: include testwindow2.kv

WindowManager:
    TestWindow1:
    TestWindow2:

testwindow1.kv

<TestWindow1>:
    name: "test1win"
    Screen:
        BoxLayout:
            orientation: 'vertical'
            MDTextField:
                id: user_mail
                hint_text: "E-Mail"
                size_hint_x: 0.8
                pos_hint: {"center_x": 0.5}
                font_size: 24
                mode: "rectangle"
            MDTextField:
                id: password
                hint_text: "Password"
                size_hint_x: 0.8
                font_size: 24
                pos_hint: {"center_x": 0.5}
                mode: "rectangle"
            MDRaisedButton:
                text: "Login"
                pos_hint: {"center_x": 0.5}
                on_release: app.login()
            Widget:

testwindow2.kv

<TestWindow2>:
    name: "test2win"
    BoxLayout:
        orientation: 'vertical'
        Screen:
            MDLabel:
                id: testwin2label
                text: "You're logged in"
            MDRaisedButton:
                id: button
                text: "Press to show database information"
                on_release: app.database_info()
            Widget:
  • Python version 3.10.4
  • Pyrebase4 version 4.5.0
mkfmtr
  • 37
  • 5

1 Answers1

0

you can try this

storage.download("/user_info/user_image/"+str(user_uid)+".png", str(user_uid)+".png")

Sparrow
  • 1
  • 1