You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在本地开发中配置使用Firebase Storage Emulator

Firebase本地Storage模拟器配置方案

你当前的配置缺失了Storage模拟器的指向声明,Firebase默认会请求云端存储服务,添加对应配置即可解决问题。

配置修改步骤

1. 新增Storage模拟器指向

在你现有的模拟器配置代码后,新增Storage模拟器的声明即可,同时可顺手修正原代码中functions模拟器地址少冒号的拼写错误,修改后的完整代码如下:

import firebase from "firebase/app"
import "firebase/auth"
import "firebase/firestore"
import "firebase/functions"
import "firebase/storage"
import "firebase/database"

 firebase.initializeApp({
   apiKey: "-------------------",
   authDomain: "http://localhost:9099",
   databaseURL: "http://localhost:9000?ns=project-name",
   projectId: "project-name",
   storageBucket: "default-bucket",
   messagingSenderId: "--------------",
   appId: "----------------------",
   measurementId: "-----------------",
})

firebase.firestore().settings({ host: "localhost:8080", ssl: false })
firebase.auth().useEmulator("http://localhost:9099")
// 修正原代码的functions模拟器地址拼写错误
firebase.functions().useEmulator("http://localhost:5001")
firebase.database().useEmulator("http://localhost:9090")
// 新增Storage模拟器配置,默认端口为9199
firebase.storage().useEmulator("localhost", 9199)

2. 前置依赖确认

  • 确保你的firebase-tools版本≥9.11.0,Web端firebase SDK版本≥8.14.0,这两个版本开始正式支持Storage模拟器
  • 启动模拟器时执行firebase emulators:start,确认控制台输出中Storage模拟器的监听端口为9199,如果你自定义过端口,要把上面代码里的9199替换为你自定义的端口

验证效果

配置完成后重新启动本地应用,上传文件时请求地址应该变为http://localhost:9199/v0/b/default-bucket/o?name=test-file.csv,代表已经成功连接本地Storage模拟器。

内容的提问来源于stack exchange,提问作者DahWaR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 17:48:02