I am currently in the process of creating a Web App (Flask) where users can log in and upload photos to Google Firebase. At one point in the code I was initially saving user uploaded photos to a local folder, but when deployed this doesn't work correctly so I decided to temporarily store it in Google Storage, analyze the faces in it, then delete it. However, I am unable to delete it from Google Storage for some reason.
Firebase Initilizations:
import pyrebase
from pyrebase.pyrebase import storage
import firebase_admin
from firebase_admin import storage, credentials
firebase = pyrebase.initialize_app(json.load(open('firebase/firebaseConfig.json')))
auth = firebase.auth()
db = firebase.database()
storage = firebase.storage()
I have not needed to delete the photos in storage before, but I am able to store Images as well as retrieve their URLs for download as seen below. I am certain the image is stored in my Google Storage and the try fails when I attempt the storage.delete()
try:
storage.child("images/temp/" + filename).put(image, userIdToken)
current_app.logger.info("[UPLOAD-IMAGE] Photo saved, grabbing url")
imageURL = storage.child("images/temp/" + filename).get_url(None)
anazlyzeInfo = recognize.facialRecognition(imageURL)
delete_temp_image_path = "images/temp/" + filename
#storage.delete(imageURL) # same error happens when URL is passed
storage.delete(delete_temp_image_path)
The error described in the exception is: 'Storage' object has no attribute 'bucket'
I looked into this for a while and tried other solutions like StorageRef
and was met with the error 'Storage' has no attribute 'ref'.
I also tried A Service Account following the Google Admin SDK setup but am not sure what to do now that I have:
cred = credentials.Certificate(json.load(open('firebase/fiddl-dev-firebase-adminsdk-stuffdnsnfsnfk.json')))
admin = firebase_admin.initialize_app(cred)
I tried working with this for a while but I could not figure out what was callable with admin.
Was I on the correct path with either of the two fixes I attempted? My use of Firebase was pretty low level before and I would think that deleting would be the same. Thanks!