Skip to content

Instantly share code, notes, and snippets.

@juliooa
Last active July 29, 2023 21:47
Show Gist options
  • Save juliooa/60fa6385c85aa30137dc2c75fe98ffed to your computer and use it in GitHub Desktop.
Save juliooa/60fa6385c85aa30137dc2c75fe98ffed to your computer and use it in GitHub Desktop.
Python script to upload an image to Firebase storage through his url
#!/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)
@tkejr
Copy link

tkejr commented Jul 30, 2020

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

@rmaran6
Copy link

rmaran6 commented Sep 17, 2020

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