-
-
Save juliooa/60fa6385c85aa30137dc2c75fe98ffed to your computer and use it in GitHub Desktop.
#!/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) |
path/to/certificate.json
is the relative path to file. For example, if you have upload_image.py
in directory /projects
and Firebase credentials file in /projects/credentials/firebase-key.json
then the path to file would be credentials/firebase-key.json
.
I am getting Error during execution of program
Traceback (most recent call last):
File "E:/tutorials/eCommerce/firebase test/demo4.py", line 8, in
image_url = sys.argv[1]
IndexError: list index out of range
line 8 : image_url = sys.argv[1] #we pass the url as an argument
how to get the URL ?
line 8 : image_url = sys.argv[1] #we pass the url as an argument
how to get the URL ?
you should know the url of your image!
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.
Hello Julio,
Unfortunately, I'm a newbie in python, and I don't really know how to give the path to the image and to the certificate. Could you give me a more specific example?