firebase python upload storage

Solutions on MaxInterview for firebase python upload storage by the best coders in the world

showing results for - "firebase python upload storage"
Dermot
04 Jul 2020
1import firebase_admin
2from firebase_admin import credentials
3from firebase_admin import storage
4
5# Import UUID4 to create token
6from uuid import uuid4
7
8cred = credentials.Certificate("path/to/your/service_account.json")
9default_app = firebase_admin.initialize_app(cred, {
10    'storageBucket': '<BUCKET_NAME>.appspot.com'
11})
12
13bucket = storage.bucket()
14blob = bucket.blob(img_src)
15
16# Create new token
17new_token = uuid4()
18
19# Create new dictionary with the metadata
20metadata  = {"firebaseStorageDownloadTokens": new_token}
21
22# Set metadata to blob
23blob.metadata = metadata
24
25# Upload file
26blob.upload_from_filename(filename=img_path, content_type='image/png')
27