Search code examples
firebasefirebase-storagefirebase-tools

Emulator Storage running but ignored


I have a firebase function that is successfully uploading a file when run in the emulator, but the file ends up on production even though I'm running the Storage Emulator

enter image description here

I'm running with the following package.json snippets in the functions directory

"dependencies": {
    "firebase-admin": "^8.13.0",
    "firebase-functions": "^3.16.0",
    ...
}
"engines": {
    "node": "14"
}

I'm initializing everything with defaults (which has worked fine in emulation and production until recently).

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();
const storage = admin.storage();
const bucket = storage.bucket();

...

const myFunction = async () => {
    const savedFile = await bucket.file(`99999999.html`).save(fileContents);
}

The code above works, although the file ends up on production, not in the emulator storage. The logs show that a production google api is being accessed.

enter image description here

This would be fine (not ideal, but workable) if I could also read the file. But when I try to run the .exits() or .download() function for the same file with bucket.file('99999999.html').download();, I get the following log entries:

enter image description here

I need to either:

  1. Get emulation for storage working to resolve this (ideal)
  2. Figure out why downloading isn't working in this case

If anyone can help me with either, I'd greatly appreciate it.


Solution

  • I have updated firebase-admin and firebase-tools packages accordingly:

    "dependencies": {
        "firebase-admin": "^10.0.0",
        "firebase-tools": "^9.23.1",
        ...
    }
    

    This resulted in a more clear error saying that the file downloaded did not match the file on the server (a hash mismatch from what I understand). I know that this is not the case, so I changed .download() to .download({validation: false}). This resolved my issue with accessing the file. It is still not storing on local emulation, but maybe that's not the intent.

    UPDATE: I figured out you have to change the bucket to see your files in emulated storage.

    enter image description here