1
votes

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

Thanks.

Code example

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

# Upload file
blob.upload_from_filename(filename)

# Make the file available for public download by those who have the link.
blob.make_public()
1

1 Answers

0
votes

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}.appspot.com'.format(project_id)
    bucket = storage.bucket(bucket_name)
    blob = bucket.blob('data/dinosaurs.json')
    blob.upload_from_filename('tests/data/dinosaurs.json')
    blob.make_public()

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.