def firebase_url(): import glob import shutil import os import time path = ('/root/Desktop/Civew_Infotech/image_merge/images/') config = { "apiKey": "AIzaQWERTYUIOPs65yzzMRdDI621eEEDgpU", "authDomain": "QWERTYUIOP-621eEED.firebaseapp.com", "databaseURL": "https://QWERTYUIOP.firebaseio.com", "storageBucket": "QWERTYUIOP-621eEED.appspot.com", } firebase = pyrebase.initialize_app(config) st = firebase.storage() a = 0 image_merge_url = [] c = 0 for filename in sorted( glob.glob('/root/Desktop/Civew_Infotech/image_merge/images/*.png'), key=os.path.getmtime): millis = int(round(time.time() * 1000)) urlfilename = str(millis) + '.png' st.child(str(urlfilename)).put(str(filename)) b = st.child(str(urlfilename)).get_url("null") print(b) image_merge_url.append(b) a = (a + 1) #===================removing all images from directory after uploading to cloud ==========# files = glob.glob('/root/Desktop/Civew_Infotech/image_merge/images/*.png') for f in files: os.remove(f) print("all images in directory removed successfully") # shutil.rmtree('/root/Desktop/Civew_Infotech/image_merge/images/*.png') return image_merge_url
def uploadwithPyre(self, filepath, secretkey, id): table = self.table cred['private_key'] = secretkey config = { "apiKey": "apiKey", "authDomain": "hepatitis-mobile.firebaseapp.com", "databaseURL": "https://hepatitis-mobile.firebaseio.com", "storageBucket": "hepatitis-mobile.appspot.com", "serviceAccount": cred } storage_path = f'image/patient/{id}/' firebase = pyrebase.initialize_app(config) storage = firebase.storage() storage.child(storage_path).put(filepath) imageurl = storage.child(storage_path).get_url(id) with connection.cursor() as cursor: query = f"UPDATE {table} SET imgurl = {repr(imageurl)} WHERE {table}.id={repr(id)}" try: cursor.execute(query) connection.commit() return ("upload successful") except: return ("unable to upload image")
def uploadImg(): from tkinter.filedialog import askopenfilename storage = firebase.storage() path = askopenfilename(initialdir="", filetypes=(('csv file', "*.csv"), ('all files', '*.*')), title="Choose and image") #insert the images storage.child(path).put(path) sub_btn['state'] = NORMAL
def uploadmv(name): config = { "apiKey": "AIzaSyBqCUjjzZ5wJ7DrQ5q1kd0EI_up5K2KFxw", # webkey "authDomain": "objproject-cd7af.firebaseapp.com", # 프로젝트ID "databaseURL": "https://objproject-cd7af.firebaseio.com", # database url "storageBucket": "objproject-cd7af.appspot.com" # storage } firebase = pyrebase.initialize_app(config) # Authentication - 필요하면 # #auth = firebase.auth() # #user = auth.sign_in_with_email_and_password("*****@*****.**", "????") # #업로드할 파일명 default = "./" # uploadfile = default + name +'/'+ name +'.gif' uploadfile = default + '/movie.gif' # #업로드할 파일의 확장자 구하기 s = os.path.splitext(uploadfile)[1] # #업로드할 새로운파일이름 #Option1 현재시간 #now = datetime.today().strftime("%Y%m%d_%H%M%S") #Option2 User's Name now = name filename = now + s # Upload files to Firebase storage = firebase.storage() storage.child("videos/" + filename).put(uploadfile) fileUrl = storage.child("videos/" + filename).get_url(1) # 0은 저장소 위치 1은 다운로드 url 경로이다. # 동영상 파일 경로를 알았으니 어디에서든지 참조해서 사용할 수 있다. print( fileUrl ) # 업로드한 파일과 다운로드 경로를 database에 저장하자. 그래야 나중에 사용할 수 있다. storage에서 검색은 안된다는 것 같다. # save files info in database db = firebase.database() d = {} d[filename] = fileUrl data = json.dumps(d) # results = db.child("files").push(data) results = db.child("files").set(data) print("OK") # Retrieve data - 전체 파일목록을 출력해 보자. 안드로이드앱에서 출려하게 하면 된다. db = firebase.database() files = db.child("files").get().val() # 딕셔너리로 반환된다. print(files) return fileUrl
# firebase db = firebase.FirebaseApplication("https://apapachatestore.firebaseio.com") # storage storageConfig = { "apiKey": "AIzaSyBAnc0Oz9Y5WEyjqyH385ue6L_UpkvLtew", "authDomain": "apapachatestore.firebaseapp.com", "databaseURL": "https://apapachatestore.firebaseio.com", "projectId": "apapachatestore", "storageBucket": "apapachatestore.appspot.com", "messagingSenderId": "529842451934", "appId": "1:529842451934:web:9a29de330667b9727ad94f" } firebase = pyrebase.initialize_app(storageConfig) storage = firebase.storage() pathCloud = "Productos/" # descarga de archivos data = db.get("Productos", "") if (data): for key in data: pathCloud = "Productos/" + data[key]["Imagen"] pathLocal = "static/" + data[key]["Imagen"] storage.child(pathCloud).download(pathLocal) #email smtp emaillist = [ '*****@*****.**', ] server = smtplib.SMTP('smtp.gmail.com', 587)
def putImage(self): storage = firebase.storage() storage.child().put