2
votes

I''m developing an android app, a web server using flask and firebase. When client app uploads an image file, the web server saves an image url in database.

And then, client app gets the image url and open image from firebase storage.

So my web server, and app don't know file name. However, to delete a file in storage, Knowing the file's name is needed. Only what I can get is file url.

How can my web server delete a file using file url?

The following code is for deleteting file using filename. I wanna change this code to deleteting file using file url.

bucket = storage.bucket('<BUCKET_NAME>')

def deleteFile(imageName):
    try:
        bucket.delete_blob('profile_images/' + imageName)
        bucket.delete()
        return True
    except Exception as e:
        print(e)
        return False
1
I'd strongly recommend persisting both the URL and the path to the file in storage to make your work easier.Doug Stevenson

1 Answers

0
votes

The Storage client in the Firebase Admin SDK is a thin wrapper around the Node.js client for Google Cloud Storage. And as far as I know the latter doesn't have a way to map the download URL back to a File.

This means that you'll have to find the path from the client using FirebaseStorage.getReferenceFromUrl(), and then pass that path to your web server. That way the JavaScript code can use the path to create a reference to the File.