代码之家  ›  专栏  ›  技术社区  ›  Paul

firebase存储:存储.ref不是函数

  •  0
  • Paul  · 技术社区  · 4 年前

    所以我看了医生的报告 https://firebase.google.com/docs/storage/web/start

    我确实:

    管理员.js

    const admin = require('firebase-admin');
    const config = require('./config.js');
    
    admin.initializeApp(config);
    
    const db = admin.firestore();
    const storage = admin.storage();
    
    module.exports = { admin, db, storage };
    

    const { admin, db, storage } = require('../util/admin');
    
    exports.postAvatar = async (request, response) => {
    
      const storageRef = storage.ref();
    
    }
    

    但我有以下错误: storage.ref is not a function

    文件中有什么遗漏吗?

    Storage {
      INTERNAL: StorageInternals {},
      storageClient: Storage {...},
      appInternal: FirebaseApp {...}
    }
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Doug Stevenson    4 年前

    admin.storage() 返回一个 Storage 对象。如果要使用它来引用默认存储桶中的文件,应该使用它的 bucket() 方法,它将为您提供 Bucket

    ref() 在SDK的任何地方。它不像JavaScript web客户端SDK。您必须学习一个不同但相似的API,才能在使用中处理内容 Cloud Storage node SDK

    const file = storage.bucket().file('/path/to/file');
    
        2
  •  0
  •   SavvyShah    4 年前

    试试下面的代码。

    const storage = storage.bucket() // you can also put your bucket-id from config
    const storageRef = storage.ref()
    

    TypeError: firebase.storage is not a function