Last active
July 29, 2023 21:47
-
-
Save juliooa/60fa6385c85aa30137dc2c75fe98ffed to your computer and use it in GitHub Desktop.
Python script to upload an image to Firebase storage through his url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import requests | |
import firebase_admin | |
from firebase_admin import credentials | |
from firebase_admin import storage | |
image_url = sys.argv[1] #we pass the url as an argument | |
cred = credentials.Certificate('path/to/certificate.json') | |
firebase_admin.initialize_app(cred, { | |
'storageBucket': '<mysuperstorage>.appspot.com' | |
}) | |
bucket = storage.bucket() | |
image_data = requests.get(image_url).content | |
blob = bucket.blob('new_cool_image.jpg') | |
blob.upload_from_string( | |
image_data, | |
content_type='image/jpg' | |
) | |
print(blob.public_url) |
code works well, Thank you!
is there any code to download files from firebase storage using python?
Does the image url have to be a local path?
Can we also use http endpoint instead?
how to get storage bucket in firebase
Hi how can I enter my url
I am really confused pls help
this is my image url https://i.ibb.co/6JxTJJB/Social-Fizz.png
image_url = sys.argv[1] #we pass the url as an argument what do I pass in this ? my url or my path or what
Is there a way I can add a timeout to the upload? I am using this on a 4G connection and want to timeout if the connection is poor.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should know the url of your image!