简体   繁体   English

如何从 Node.js 中获取 Firebase 中的默认存储桶名称?

[英]How do I get the default bucket name in Firebase, from inside Node.js?

I want to avoid hard coding the default bucket name in a Firebase project.我想避免在 Firebase 项目中对默认存储桶名称进行硬编码。 How do I get it on server side?我如何在服务器端获取它?

const admin = require("firebase-admin");
const defaultBucket = admin.storage().bucket();
const defaultBucketName = ...?

Get bucket name: 获取存储桶名称:

const defaultBucketName = defaultBucket.name;

Ref: Interface: ObjectMetadata 参考: 接口:ObjectMetadata

It turns out that the information is stored in an environment variable but not imported into the admin tooling directly.事实证明,信息存储在环境变量中,但没有直接导入管理工具。 So the best way I have found to prepare your environment to serve the default bucket name is as follows:因此,我发现准备环境以提供默认存储桶名称的最佳方法如下:

const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG!);

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  storageBucket: firebaseConfig.storageBucket,
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Firebase 函数中获取默认存储桶名称? - How to get the default bucket name in Firebase Functions? 如何将 Firebase 连接到 Node.JS 项目? - How to connect Firebase to a Node.JS project? 将大于 1MB 的文件上传到 S3 Bucket (Node.js) 时出现错误代码 500 - Get the error code 500 when I upload a file size > 1MB to S3 Bucket (Node.js) 如何使用 Node.js 和“firebase-admin”SDK 查询 Firebase? - How to query Firebase with Node.js and "firebase-admin" SDK? 如何阻止 nodejs-firestore 写入阻止 node.js 事件循环? - How do I stop nodejs-firestore writes from blocking the node.js event loop? 如何从 Node.js 中的 S3 getObject 获取响应? - How to get response from S3 getObject in Node.js? 从 Node.js 中的 Firebase 实时数据库中选择特定属性 - Select specific properties from Firebase Realtime Database in Node.js 如何使用 node.js 从后端刷新 firebase 令牌 - how to refresh firebase token from back-end using node.js Node.js 从服务器上传图片文件到firebase失败 - Node.js failed to upload image file to firebase from the server 如何使用查询从 Firebase 9 js 中删除文档? - How do I delete a document from Firebase 9 js using a query?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM