Home > database >  Firebase Functions and Storage getSignedUrl with Emulators
Firebase Functions and Storage getSignedUrl with Emulators

Time:12-16

I have a function that generates a signed URL for the requested storage path provided the user has permissions to read. I had to implement this due to current limitations in the storage cross service rules.

When I run the emulators a URL is returned for my production site.

From the docs: https://firebase.google.com/docs/emulator-suite/connect_storage#admin_sdks

Note that the Cloud Functions emulator is automatically aware of the Cloud Storage for Firebase emulator so you can skip this step when testing integrations between Cloud Functions and Cloud Storage for Firebase emulators. The environment variable will be automatically set for the Admin SDK in Cloud Storage for Firebase.

However I cannot figure out how to get signed URL for my storage emulators. Am I doing something wrong or is this not possible?

const expireDate = Date.now()   1000 * 60 * 15; // 15 minutes

const storageRef =  admin.storage().bucket().file(path);
const url = await storageRef.getSignedUrl({
    action: "read",
    expires: expireDate,
    });
return url[0];

I can confirm that both functions and storage are running within the emulators. firebase emulators:start --import ./local-export

In production mode everything works fine, with emulators running all URL's fail as the the blobs do not exist in production. Any solutions?

CodePudding user response:

Currently, getSignedUrl() method is not supported on emulators and it is a known issue. There already a github issue is raised for the same.

And Google team mentioned that they were not planned to support this.

We currently only have minimal API support for the Cloud API interface, which sadly is completely different and substantially larger than Firebase's, so we're not aiming for 100% compatibility because of this.

Signed URLs are not currently planned to be supported, but we can leave this open for a bit and if you're interested in signed URLs just hit this message with an emoji reaction and we'll keep an eye on it and prioritize accordingly.

If you are really affected, you can add your concern there.

  • Related