firebase / firebase/firebase-admin-node

Storage `bucket.exists()` always returns false for firebase emulator

Abierto
#2,447 0 comentarios 1 reacción 0 asignados Ver en GitHub
api: storage
Lenguaje dominante
TypeScript
Estrellas
1.7k
Forks
419
Merge medio
3 d 10 h
PR fusionados (30 d)
16

Descripción

### [READ] Step 1: Are you in the right place?

* For issues related to __the code in this repository__ file a Github issue.
* If the issue pertains to Cloud Firestore, read the instructions in the "Firestore issue"
template.
* For general technical questions, post a question on [StackOverflow](http://stackoverflow.com/)
with the firebase tag.
* For general Firebase discussion, use the [firebase-talk](https://groups.google.com/forum/#!forum/firebase-talk)
google group.
* For help troubleshooting your application that does not fall under one
of the above categories, reach out to the personalized
[Firebase support channel](https://firebase.google.com/support/).

### [REQUIRED] Step 2: Describe your environment

* Operating System version: Ubuntu
* Firebase SDK version: firebase-admin@12.0.0 firebase-tools@13.1.0
* Firebase Product: storage
* Node.js version: 18.16.1
* NPM version: 9.5.1

### [REQUIRED] Step 3: Describe the problem

#### Steps to reproduce:

Create basic project with storage and functions setup for emulation: (functions only used to call storage bucket methods)
```json
// firebase.json
"emulators": {
"functions": {
"port": 5001
},
"storage": {
"port": 9199
},
// ...rest of config
```
Run emulator with `firebase emulators:start --only storage,functions`
Verify storage bucket exists in emulator and the name is matched in firebase config showing `storage_bucket` as the default
Hit the firebase function to run the storage bucket code
Calling `bucket.exists()` from firebase function _always_ returns false.

**Expected outcome:**
Calling `bucket.exists()` from firebase function return `true` when accessing the default bucket.

#### Relevant Code:

```ts
import { onRequest } from 'firebase-functions/v2/https';
import { getStorage } from 'firebase-admin/storage';

export const foo = onRequest(async (req, res) => {
const storage = getStorage();
console.log('APP STORAGE BUCKET:', storage.app.options.storageBucket);

const bucket = storage.bucket();
console.log('DEFAULT STORAGE BUCKET:', `name=${bucket.name}`, `id=${bucket.id}`);

const exists = await bucket.exists();
console.log('BUCKET EXISTS?:', exists);

res.send(`BUCKET EXISTS?: ${exists}`);
});
```

#### Images

Console output:
![image](https://github.com/firebase/firebase-admin-node/assets/625203/f7878cfa-1f10-4f13-9cf8-38e3751802db)

Emulator Storage: (name of bucket matches id in code)
![image](https://github.com/firebase/firebase-admin-node/assets/625203/231ab666-a54e-40f0-99d7-cb64238e2d94)

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.