gpt4 book ai didi

node.js - Cloud Storage for Firebase 访问错误 "admin.storage(...).ref is not a function"

转载 作者:搜寻专家 更新时间:2023-10-31 22:23:43 25 4
gpt4 key购买 nike

我正在使用 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()

但是它抛出一个错误说

TypeError: admin.storage(...).ref is not a function

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
}

Node -v =>v7.7.4

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

最佳答案

您正在使用 Cloud Functions 和 Firebase Admin SDK 尝试访问您的存储桶。您引用的入门指南是在谈论客户端 Web 应用程序和 Firebase 的 Web API,而不是 Admin。那里的功能不同,因为它使用不同的 SDK(即使它们的名称相同)。

您尝试访问的Storage 对象没有ref() 函数,只有appbucket( )

https://firebase.google.com/docs/reference/admin/node/firebase-admin.storage

尝试直接使用 Google Cloud API:

https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-nodejs

-

编辑:此编辑只是为了避免用两年前的帖子吓唬人。截至 2020 年 5 月,上述答案仍然适用。

关于node.js - Cloud Storage for Firebase 访问错误 "admin.storage(...).ref is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47810166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com