import firebase_admin from firebase_admin import credentials from firebase_admin import storage # Import UUID4 to create token from uuid import uuid4 cred = credentials.Certificate("path/to/your/service_account.json") default_app = firebase_admin.initialize_app(cred, { 'storageBucket': '.appspot.com' }) bucket = storage.bucket() blob = bucket.blob(img_src) # Create new token new_token = uuid4() # Create new dictionary with the metadata metadata = {"firebaseStorageDownloadTokens": new_token} # Set metadata to blob blob.metadata = metadata # Upload file blob.upload_from_filename(filename=img_path, content_type='image/png')
Here is what the above code is Doing:
1. We’re creating a new token using UUID4
2. We’re creating a new dictionary with the metadata
3. We’re setting the metadata to the blob
4. We’re uploading the file
Now, we can access the image using the following URL:
https://firebasestorage.googleapis.com/v0/b/