How to retrieve image from Firebase Storage using Python?

后端 未结 1 2020
悲&欢浪女
悲&欢浪女 2021-02-11 00:29

I have already store my image to Firebase Storage, and I need to take it out by using Python code. Can I retrieve the image by using any URL? Or is there any way to retrieve it

相关标签:
1条回答
  • 2021-02-11 00:53

    This is what I use. Hope it helps.

    import firebase_admin
    from firebase_admin import credentials
    from firebase_admin import storage
    
    # Fetch the service account key JSON file contents
    cred = credentials.Certificate("credentials.json")
    
    # Initialize the app with a service account, granting admin privileges
    app = firebase_admin.initialize_app(cred, {
        'storageBucket': '<BUCKET_NAME>.appspot.com',
    }, name='storage')
    
    bucket = storage.bucket(app=app)
    blob = bucket.blob("<your_blob_path>")
    
    print(blob.generate_signed_url(datetime.timedelta(seconds=300), method='GET'))
    

    It generates a public URL (for 300 secs) for you to download your files.

    For example, in my case, I use that URL to display stored pictures in my django website with <img> tag.

    Here is the doc for more usefull functions.

    0 讨论(0)
提交回复
热议问题