google cloud storage make object public through python Firebase admin SDK

Dan Hampton Source

I'm trying to make an excel file I upload to Firebase storage (google cloud storage) publicly available as a link. When I use the method blob.make_public() I get a Forbidden 403 error: Insufficient permission.

I'm using the Firebase Admin SDK for python. As far as I can tell in the IAM part of the cloud console the admin SDK has Editor and Storage Object Admin roles. Any way to make the uploaded object public through python?

Haven't found anything else that works in the docs: Python GCS API


Code example

# Access google cloud storage bucket
bucket =
# Blob - Google's wrapper for objects stored in buckets
destination_blob_name = 'excelReports/' + filename + '_' +"%b_%d_%Y_%H_%M_%S")
blob = bucket.blob(destination_blob_name)

# Upload file

# Make the file available for public download by those who have the link.


answered 8 months ago Hiranya Jayathilaka #1

I just tried the following integration test case, and it worked as expected.

from firebase_admin import storage

def test_make_public(project_id):
    bucket_name = '{0}'.format(project_id)
    bucket = storage.bucket(bucket_name)
    blob = bucket.blob('data/dinosaurs.json')

After the test I could find the data/dinosaurs.json file in the GCS bucket, marked as public.

Make sure you're using the correct service account file to initialize the Admin SDK. And also ensure the bucket you're trying to access belongs to the same Firebase project as the credential. Also ensure that your file upload completes successfully -- i.e. the file actually ends up in the intended location.

comments powered by Disqus