Reputation: 1
I tried to make this video uploading app to my firebase storage, but I'm stuck at this problem. When the upload button is pressed, the filechooser is opened and if i select a file, it gets uploaded to firebase. But if i cancel and close the filechooser, it gives an error:
Traceback (most recent call last): File "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\plyer\platforms\win\filechooser.py", line 108, in run self._handle_selection(self.selection) File "C:\Users\Dheeraj\Desktop\kivy codes\Dheeraj.py", line 949, in selected Directory=selection[0] IndexError: list index out of range [INFO ] [Base ] Leaving application in progress...
I am unaware if this file chooser works on android or not. If it does not, please help me with this code too.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivymd.uix.dialog import MDDialog
import json
from plyer import filechooser
from kivymd.uix.button import MDFlatButton
import requests
import pyrebase
from kivmob import KivMob, TestIds, RewardedListenerInterface
from kivy.properties import NumericProperty, StringProperty,BooleanProperty
from kivymd.uix.label import MDLabel
from kivy.uix.relativelayout import RelativeLayout
import re
from kivy.garden.notification import Notification
from kivymd.uix.behaviors import FakeRectangularElevationBehavior
from kivy.uix.behaviors import ButtonBehavior
from kivymd.uix.floatlayout import MDFloatLayout
import plyer
help_str='''
ScreenManager:
MainScreen:
<MainScreen>:
name: 'mainscreen'
MDFloatLayout:
id:floate
Video:
id:vid
MDRaisedButton:
id:upload
text:'Upload'
pos_hint:{'center_x':.5, 'center_y':.05}
on_release:
app.file_chooser()
upload.disabled=True
'''
class MainScreen(Screen):
pass
sm = ScreenManager()
sm.add_widget(MainScreen(name = 'mainscreen'))
class LoginApp(MDApp):
def build(self):
self.strng = Builder.load_string(help_str)
self.url = "**confidential**.json"
return self.strng
def file_chooser(self):
filechooser.open_file(on_selection=self.selected)
def selected(self,selection):
configure={
'apiKey': "**confidential**",
'authDomain': "**confidential**",
'databaseURL': "**confidential**",
'projectId': "**confidential**",
'storageBucket': "**confidential**",
'messagingSenderId': "**confidential**",
'appId': "**confidential**",
'measurementId': "**confidential**",
'serviceAccount':"**confidential**",
'databaseURL':'**confidential**'
}
firebase=pyrebase.initialize_app(configure)
storage=firebase.storage()
Directory=selection[0]
Name=re.findall('[ \w-]+\..*',Directory)
storage.child(str(f"{Name}")).put(str(f"{Name[0]}"))
if selection==true:
self.root.ids.vid.source=firebase
if __name__=="__main__":
LoginApp().run()
Upvotes: 0
Views: 304
Reputation: 1
i think i've figured it out all i have to do was indent the code of selected function under its own if selection==True statement. thanks to everyone who tried to help 🙏.
def selected(self,selection):
if selection==true:
self.root.ids.vid.source=firebase
configure={
'apiKey': "**confidential**",
'authDomain': "**confidential**",
'databaseURL': "**confidential**",
'projectId': "**confidential**",
'storageBucket': "**confidential**",
'messagingSenderId': "**confidential**",
'appId': "**confidential**",
'measurementId': "**confidential**",
'serviceAccount':"**confidential**",
'databaseURL':'**confidential**'
}
firebase=pyrebase.initialize_app(configure)
storage=firebase.storage()
Directory=selection[0]
Name=re.findall('[ \w-]+\..*',Directory)
storage.child(str(f"{Name}")).put(str(f"{Name[0]}"))
Upvotes: 0