Cloud Storage for Firebase访问错误"admin.storage(...).ref不是函数"; [英] Cloud Storage for Firebase access error "admin.storage(...).ref is not a function"

查看:72
本文介绍了Cloud Storage for Firebase访问错误"admin.storage(...).ref不是函数";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cloud Storage for Firebase,却不知道如何访问存储文件

I am working with Cloud Storage for Firebase and can't figure out how to to access storage files

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

According to https://firebase.google.com/docs/storage/web/start official guide and https://firebase.google.com/docs/storage/web/create-reference this code should be returning root reference

let admin = require('firebase-admin')
admin.initializeApp({...})
let storageRef = admin.storage().ref()

但是抛出错误

TypeError: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
}

节点-v => v7.7.4

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

My end goal it to download files or upload a pdf file to storage.

推荐答案

您正在使用Cloud Functions和Firebase Admin SDK尝试访问您的存储桶.您引用的入门指南"是在谈论带有Firebase Web API而不是管理员的客户端Web Apps.那里的功能不同,因为它使用了不同的SDK(即使它们的名称相同).

You are using Cloud Functions and the Firebase Admin SDK to try and access your bucket. The Getting Started guide you cited is talking about client sided Web Apps with the Web API for Firebase not the Admin one. The functionality there is different, because it uses a different SDK (even if their names are the same).

您要访问的 Storage 对象没有 ref()函数,只有 app bucket().

The Storage Object you are trying to access doesn't have the ref() functions, only app and bucket().

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

尝试直接使用Google Cloud API:

Try using the Google Cloud APIs directly:

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

-

此项编辑只是为了避免吓scar两年前发布的帖子的人.截至2020年5月,上述答案仍然适用.

This edit is only to stop scaring people with an post from two years ago. The answer above still applies as of May 2020.

这篇关于Cloud Storage for Firebase访问错误"admin.storage(...).ref不是函数";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆