Home > Enterprise >  How do I download image from firebase storage folder with python?
How do I download image from firebase storage folder with python?

Time:11-19

I want to download image from firebase storage which the resouce folder

1

can anyone teach me how to do?

my english is not good forgive me

CodePudding user response:

This code will help you download any image in Firebase, you will find in your local folder as "img.png"

The credentials.json should be in the same folder you run this code in and you can retrieve it from Firebase, its particular to your account

In my case my storage bucket is called 'aisparkdev-tinder.appspot.com'

When generating the blob variable, the string is just the path to your image.

import urllib
import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage
cred = credentials.Certificate("credentials.json")

    # Initialize the app with a service account, granting admin privileges
appF = firebase_admin.initialize_app(cred, 
                                    {'storageBucket': 'aisparkdev-tinder.appspot.com',}, 
                                    name='storage')

bucket = storage.bucket(app=appF)

blob = bucket.blob("profileImages/" profilePic ".jpg")
urllib.request.urlretrieve(blob.generate_signed_url(datetime.timedelta(seconds=300), method='GET'), ".\\img.png")
  • Related