Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ChromeQ opened this issue Feb 6, 2024 · 0 comments
Open

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

ChromeQ opened this issue Feb 6, 2024 · 0 comments

Comments

@ChromeQ
Copy link

ChromeQ commented Feb 6, 2024

[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
    with the firebase tag.
  • For general Firebase discussion, use the 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.

[REQUIRED] Step 2: Describe your environment

[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)

// 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:

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

Emulator Storage: (name of bucket matches id in code)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants