5

I'm trying to setup the storage emulator for my firebase project. I am using the Go admin sdk. However it seems to be ignored despite following the documented process.

App initialization:

func App(ctx context.Context) (*firebase.App, error) {
    opt := option.WithCredentialsFile("firebase-service-account.json")
    config := firebase.Config{
        StorageBucket: "<my-project-id>.appspot.com",
    }
    app, err := firebase.NewApp(ctx, &config, opt)
    if err != nil {
        return nil, fmt.Errorf("error initializing app: %v", err)
    }
    return app, nil
}

.env file loaded on startup:

FIRESTORE_EMULATOR_HOST="localhost:8081"
FIREBASE_STORAGE_EMULATOR_HOST="localhost:9199"
GCLOUD_PROJECT="my-project-id"

I also tried manually setting these by running: export FIREBASE_STORAGE_EMULATOR_HOST="localhost:9199" and export GCLOUD_PROJECT="my-project-id".

However, when when writing to the default bucket, my blob appears in the actual firestore console for storage, not the storage emulator.

I pulled the GCLOUD_PROJECT value from my service account json file, the project_id field specifically. Also confirmed that 9199 is the port that storage is running on.

Besides setting those FIREBASE_STORAGE_EMULATOR_HOST and GCLOUD_PROJECT am I missing something else?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

2 Answers2

0

The variable name is STORAGE_EMULATOR_HOST.

See: https://pkg.go.dev/cloud.google.com/go/storage

mabg
  • 1,894
  • 21
  • 28
0

Firebaser Here,

You're correct in that your current setup should have been sufficient. I've filed an issue in the GO SDK Repo so that this can get addressed.

In the meanwhile the current fix, as @mabg pointed out, is to set the STORAGE_EMULATOR_HOST variable as well Code Sample

Abhinav S
  • 21
  • 3