简体   繁体   English

如何在存储具有完全读/写管理员权限的情况下使Firebase Cloud功能正常运行?

[英]How to make a Firebase Cloud function with full read/write admin powers on storage?

I have created some functions that upload and download files from firebase storage with cloud functions using the Firebase SDK and they work. 我创建了一些使用Firebase SDK使用云功能从Firebase存储上载和下载文件的功能,它们可以正常工作。 I would like for the functions to be executed as admin so that they don't need to abide by the storage rules. 我希望这些功能以admin身份执行,因此它们不需要遵守存储规则。

I have replaced the firebase SDK with the admin SDK but I found out that my firebase.storage().ref reference doesn't work anymore and by reading around some docs I have realized I now need to use the google cloud services system instead. 我已将firebase SDK替换为admin SDK,但是我发现firebase.storage()。ref引用不再起作用,通过阅读一些文档,我意识到我现在需要使用Google Cloud Services系统。

So my question is, is there a way to have a cloud function have administrator powers on the entire firebase project without having to switch to google cloud functions and if not, is there a work around to do that so that I can somehow authorize my cloud function to have full read/write powers on the entire storage? 所以我的问题是,是否有一种方法可以让云功能具有整个Firebase项目的管理员权限,而不必切换到Google云功能;如果没有,是否有解决方法,以便我可以某种方式授权我的云功能以在整个存储上具有完全的读/写能力? I am puzzled! 我很困惑!

Here is a snippet of my code: 这是我的代码片段:

const firebase = require('firebase-admin');

const functions = require('firebase-functions');

require("firebase-admin")
require("firebase")
require("firebase/storage");

var serviceAccount = require("serviceAccount.json");

var config = {
    [...]
    credential: firebase.credential.cert(serviceAccount)
  };
  firebase.initializeApp(config);

  var storage = firebase.storage();
  var storageRef = storage.ref(); //This returns .ref() is not a function

The Firebase client libraries are not intended to work on backend server environments. Firebase客户端库不适用于后端服务器环境。 The Firebase Admin SDK is meant for backends, but the API to access Cloud Storage is different than the client SDK. Firebase Admin SDK适用于后端,但是访问Cloud Storage的API与客户端SDK不同。 The Admin SDK just wraps the Cloud Storage server SDKs. Admin SDK仅包装了Cloud Storage服务器SDK。 So for node environments, you are actually just going to use the Cloud Storage Node.js client . 因此,对于节点环境,实际上您将只使用Cloud Storage Node.js客户端

When you call: 你打电话时:

const admin = require('firebase-admin')
const storage = admin.storage()

you are getting a Storage object from the node SDK. 您正在从节点SDK获取存储对象。 It doesn't have a ref() method. 它没有ref()方法。 You will need to get a Bucket object and use that instead: 您将需要获取一个Bucket对象,并使用该对象:

const bucket = storage.bucket()

From here, you should continue to use the API docs I'm linking to. 从这里开始,您应该继续使用我链接到的API文档。

暂无
暂无

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

相关问题 Cloud Storage for Firebase 访问错误“admin.storage(...).ref is not a function” - Cloud Storage for Firebase access error “admin.storage(…).ref is not a function” 如何使用云功能制作缩略图并将其放置在Firebase存储中的特定文件夹中? - how to make thumbnail and place it in the particular folder in Firebase storage using cloud function? 如何使用 Cloud Function 从 Cloud Storage 获取 Firebase 的 object? - How to get object from Cloud Storage for Firebase using Cloud Function? 在云中使用 firebase-admin 将 Base64 编码的 PDF 字符串保存到 firebase 存储 function - Saving a Base64-encoded PDF string to firebase storage using firebase-admin in a cloud function 如何从 Firebase 云 Function 中删除 Firebase 存储文件夹? - How to delete a Firebase Storage folder from a Firebase Cloud Function? 如何更正 Firebase 云 Function 管理员参考不是 function 错误 - How to correct Firebase Cloud Function admin reference not a function error 如何使用Firebase云功能存储创建文件夹 - How can make folder with Firebase Cloud Functions Storage 在单个 Firebase 项目中读取/写入多个 DB - 管理员 SDK Cloud Functions - Read/Write to multiple DBs in single Firebase Project - Admin SDK Cloud Functions Firebase:云函数+存储读取文件 - Firebase: Cloud Functions + Storage Read File 如何避免在云存储事件中对文件夹执行Firebase功能 - How to avoid performing a firebase function on folders on cloud storage events
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM