Uploading files to the storage emulator using the admin sdk

Hey everyone, I’m wondering if you’ve had any luck uploading files to the storage emulator using the admin sdk? I’ve defined FIRESTORE_STORAGE_EMULATOR_HOST and am uploading like so


bucket.upload('./db-seed/files.json', {
  destination:
    'users-0/lhlA9hDvVmL2N8g6780CgwvERkXp/projects/project-id-1/files.json'
})```
but this keeps adding the file to the real storage.

I’m initialising the app like so, and can successfully upload data to the firestore emulator,  but not the storage emulator
```admin.initializeApp({
  projectId: ...,
  credential: admin.credential.cert({
    projectId: ...,
    private_key: ...,
    client_email: ...
  }),
  storageBucket: ...
});```

Any ideas? I’m all out :thinking_face:

Show me firebase.json and how you’ve defined your FIRESTORE_STORAGE_EMULATOR_HOST

Thanks …

  "storage": {
    "rules": "firebase-storage.rules"
  },
  "emulators": {
    "firestore": {
      "port": 8080
    },
    "auth": {
      "port": 8081
    },
    "database": {
      "port": 8082
    },
    "storage": {
      "port": 9199
    },
    "ui": {
      "enabled": true
    }
  }
}```

And have these npm scripts

"emulator-hosts": "FIREBASE_AUTH_EMULATOR_HOST=\"localhost:8081\" FIRESTORE_STORAGE_EMULATOR_HOST=\"localhost:8082\" FIRESTORE_EMULATOR_HOST=\"localhost:8080\" FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:8082\"",```

As i said this works fine for seeding the firestore

To set those variables, you should add it to actual file

// test settings and vars

process.env.GCLOUD_PROJECT = projectId;
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080';

const testEnv = functions({
    projectId: projectId,
});```

This is example from my unit tests

Thanks once again, but no luck :confused:

I’ll set up a minimal example repo…