Cloud Functions:如何上传额外的文件以在代码中使用?

neu*_*t47 7 node.js firebase google-cloud-platform google-cloud-functions

我需要访问protoc我的代码中的文件。在本地我只是把它放在文件夹中,但是如何从部署的 Firebase 函数中获取这个文件?

const grpc = require('grpc');
const PROTO_PATH = __dirname + '\\protos\\prediction_service.proto';

exports.helloWorld = functions.https.onRequest((request, response){
    var tensorflow_serving = grpc.load(PROTO_PATH).tensorflow.serving;
...
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*ave 7

对于 Firebase 函数,我发现这种方式最简单:

  1. 将您的 .proto 文件放入 firebase项目的函数文件夹(index.js 和 package.json 所在的位置)。
  2. 使用 CLI 命令正常部署您的函数 firebase deploy --only functions

正如您在此处看到的,该文件会自动添加到 GCP 中的项目中:

在此处输入图片说明

你可以在你的 node.js 项目中访问它:

protobuf.load(__dirname + '/schema.proto')
Run Code Online (Sandbox Code Playgroud)


Lun*_*ast 6

您想上传 3 个文件来部署您的云功能:

  • 索引.js
  • 包.json
  • 预测服务.proto

为了通过开发者控制台执行此操作,您需要:

  1. 转到 Google Cloud Developer Console > Cloud Functions > 创建函数
  2. 在“源代码”字段中,选择:
    • “ZIP 上传”并选择一个包含 3 个文件的 zip 文件,
    • “ZIP from Cloud Storage”并在 GCS 上选择文件位置,
    • “云源存储库”并提供您的存储库详细信息
  3. 填写其余字段,然后单击“创建”

部署后,在函数的源选项卡中,您将看到显示的三个文件。

或者,您可以使用 gcloud 通过以下命令部署文件:

gcloud beta functions deploy <functionName> --source=SOURCE
Run Code Online (Sandbox Code Playgroud)

其中 source 可以是 Google Cloud Storage 上的 ZIP 文件、对源存储库的引用或本地文件系统路径。我建议查看此命令的文档以获取完整详细信息。


Nie*_*ost 6

当您在 TypeScript 中使用 Firebase Cloud Functions 时(您的代码在 中functions/src/index.ts),您需要将其他文件放入functions/lib