firebase

How to use firebase download urls from storage emulator on physical device


I am developing a react native app using firebase. I followed the instructions in these posts to allow a development build of my app on my iPhone to access the firebase emulators running on my laptop. It works great:

https://medium.com/@Toglefritz/connecting-physical-devices-to-your-firebase-emulator-dae629c6d192

Firebase Firestore emulator on physical IOS / Android device

However, I am trying to figure out if there is a way for firebase file downloadUrls to work properly with this setup?

In other words, in one of my firebase functions, which also runs on the emulator, I process a file in storage and save its downloadUrl to a database:

const { getDownloadURL } = require('firebase-admin/storage');

const convertedUrl = await getDownloadURL(newVideoFile);

The download url gets generated with a value such as:

http://127.0.0.1:9199/v0/b/myapp.appspot.com/o/path%2Fto_file%2Fmy_video.mp4?alt=media&token=abcdef

Then, in my app, I try to download this file using the url, but since I am on my physical device, the download doesn't work, I'm assuming because the device can't access 127.0.0.1:9199. I also tried changing the host of the download url to:

http://0.0.0.0:9199/v0/b/myapp.appspot.com/o/path%2Fto_file%2Fmy_video.mp4?alt=media&token=abcdef

But that doesn't work either. Is there any way for me to access these storage emulator download URLs from my local device?


Solution

  • The 127.0.0.1 in the download URL indicates that it's a file on the local machine, so whichever machine you access the URL on. So that URL will only work on the machine where you're running the emulator.

    If you substitue the 127.0.0.1 in that download URL by the IP address of the machine where you run the emulator, you should be able to access the file from other machines in the network too.