Cloud Storage for Firebase访问错误“ admin.storage(...)。ref不是函数”

Abd*_*lah 7 node.js firebase firebase-storage firebase-admin

我正在使用Cloud Storage for Firebase,无法弄清楚如何访问存储文件

根据https://firebase.google.com/docs/storage/web/start官方指南和https://firebase.google.com/docs/storage/web/create-reference,此代码应返回根引用

let admin = require('firebase-admin')
admin.initializeApp({...})
let storageRef = admin.storage().ref()
Run Code Online (Sandbox Code Playgroud)

但这引发了错误

TypeError:admin.storage(...)。ref不是一个函数

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {...},
  "dependencies": {
    "@google-cloud/storage": "^1.5.1",
    "firebase": "^4.8.0",
    "firebase-admin": "~5.4.2",
    "firebase-functions": "^0.7.1",
    "pdfkit": "^0.8.3",
    "uuid": "^3.1.0"
  },
  "private": true
}
Run Code Online (Sandbox Code Playgroud)

节点-v => v7.7.4

我的最终目标是下载文件或将pdf文件上传到存储。

Rae*_*lan 8

您正在使用Cloud Functions和Firebase Admin SDK尝试访问您的存储桶。您引用的入门指南讨论的是使用Web Api for Firebase而不是管理员使用的客户端Web Apps。那里的功能不同,因为它是不同的SDK(即使名称保持不变)。Storage您尝试访问的对象没有ref()功能,只有appbucket()https://firebase.google.com/docs/reference/admin/node/admin.storage.Storage

尝试直接使用Google Cloud API:https//cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-nodejs

  • 这是常见混乱的完美解释。我认为Firebase的文档可能会更好。您的简单回答使我节省了大量时间。谢谢! (6认同)
  • 截至 2020 年 3 月,情况仍然如此吗?如果没有,是否计划将存储 api 包含到管理 sdk 中? (2认同)
  • 截至 2020 年 4 月,情况仍然如此。Firebase 的文档可以更好地强调这一点。 (2认同)
  • https://firebase.google.com/docs/reference/admin/node/admin.storage.Storage 链接未找到,您可以更新替代链接吗? (2认同)