标签: google-cloud-functions

Firebase OnWrite的云功能

我正在研究Firebase的新云功能,它说在进行OnWrite时你应该注意不要将数据保存回同一个Child.(这将再次触发触发器).

所以我想弄清楚,如何在记录上设置修改日期?

firebase firebase-realtime-database google-cloud-functions

16
推荐指数
2
解决办法
1万
查看次数

你能在Firebase云功能中呼叫FFMPEG吗?

根据Firebase云功能文档,您可以在云功能中利用ImageMagick:https: //firebase.google.com/docs/functions/use-cases

是否有可能做类似的事情,但呼吁FFMPEG而不是ImageMagick?虽然缩略图像非常棒,但我还希望能够将传入图像附加到存储在Firebase存储上的视频文件中.

ffmpeg firebase google-cloud-functions

16
推荐指数
4
解决办法
7833
查看次数

将敏感信息传递给云功能

是否有"官方"解决方案将敏感信息(如API密钥)传递给Google Cloud Functions?特别是避免将此信息作为参数传递给函数会很好,因为它对于每次调用都是相同的.AWS Lambda具有使用加密环境变量的内置解决方案.Google Cloud Functions是否有类似的方法?

我可以想象使用云存储桶或云数据存储,但这感觉非常手动.

google-cloud-functions

16
推荐指数
3
解决办法
4096
查看次数

Firebase HTTP云功能 - 一次读取数据库

我有一个Firebase HTTPs功能.该函数需要根据查询参数从Firebase数据库中读取值,并根据此数据返回结果.

Firebase JS SDK说使用以下方法执行此操作:

return firebase.database().ref('/users/' + userId).once('value').then(function(snapshot) {
  var username = snapshot.val().username;
  // ...
});
Run Code Online (Sandbox Code Playgroud)

但是,云功能示例包括:

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

functions.database.ref('/');
Run Code Online (Sandbox Code Playgroud)

但是数据库引用没有这个方法once,只有onWrite(https://firebase.google.com/docs/reference/functions/functions.database.RefBuilder).这显然适用于DB写入功能,而不是HTTP功能.

在HTTP函数中有没有正确的方法从数据库中读取一次?我可以使用普通的Firebase SDK,还是有更好的方法?

谢谢.

javascript firebase firebase-realtime-database google-cloud-functions

16
推荐指数
2
解决办法
2万
查看次数

VS Code中的函数调试

VS Code集成终端我运行firebase serve --only functions,hosting 然后在调试选项卡中我创建了默认的launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${file}"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我想调试服务器端(functions/index.js)而不是客户端.

我从https://code.visualstudio.com/docs/nodejs/nodejs-debugging尝试了一些配置而没有运气.

如何在VS Code中调试Firebase功能?

debugging firebase visual-studio-code google-cloud-functions

16
推荐指数
2
解决办法
4392
查看次数

通过file.createWriteStream()流式传输到GCP时,获取ESOCKETTIMEOUT,ECONNRESET或套接字挂起大文件

在尝试通过Google Cloud功能将大文件(> 50MB)上传到Google云端存储时,我会根据我设置的选项遇到这些异常:

  • 在设置请求选项'forever:false'时,我得到:错误:套接字挂起
  • 在设置请求选项'resumable:true'时,我得到:错误:写ECONNRESET
  • 在设置请求选项'resumable:false'时,我得到:错误:ESOCKETTIMEDOUT with resumable:false

这是我使用的代码:

function uploadFile(bucketName, filename, data) {
  console.log("Starting uploading blob...");
  const Storage = require('@google-cloud/storage');

  console.log("Creating client...");
  const storage = new Storage();
  storage.interceptors.push({
      request: function(reqOpts) {
        reqOpts.forever = false;
        return reqOpts
      }
    });

  console.log("Getting bucket " + bucketName + "...");
  const bucket = storage.bucket(bucketName);
  console.log("Creating file " + filename + "...");
  const file = bucket.file(filename);
  console.log("Creating write stream...");

  var writeStream = file.createWriteStream({
    metadata: {
      contentType: 'plain/text'
    },
    resumable: false
  });

  writeStream.on('error', function(e) { console.error("An …
Run Code Online (Sandbox Code Playgroud)

sockets file-upload node.js google-cloud-storage google-cloud-functions

16
推荐指数
1
解决办法
1463
查看次数

Google Cloud Functions Python日志记录问题

我不确定该怎么说,但是,我感觉好像有些东西被Google更改了,而我却一无所知。我曾经从日志记录仪表板内Google Cloud Console中的python Cloud Functions中获取日志。现在,它刚刚停止工作。

所以我去研究了很长时间,我刚刚做了一个日志你好世界python Cloud Function:

import logging

def cf_endpoint(req):
    logging.debug('log debug')
    logging.info('log info')
    logging.warning('log warning')
    logging.error('log error')
    logging.critical('log critical')
    return 'ok'
Run Code Online (Sandbox Code Playgroud)

这是我的main.py,我将其部署为带有http触发器的Cloud Function。

由于我拥有所有“调试”级别日志的日志提取排除过滤器,因此在日志记录仪表板中什么都看不到。但是当我删除它时,我发现了这一点:

日志记录仪表板截图

因此,似乎将python内置日志记录解析为stackdriver的操作停止了对日志严重性参数的解析!对不起,如果我看起来很傻,但这是我唯一能想到的:/

你们对此有任何解释或解决方案吗?我做错了吗?

预先感谢您的帮助。

logging python-3.x google-cloud-platform google-cloud-functions

16
推荐指数
4
解决办法
2390
查看次数

firebase 函数 Puppeteer 找不到 Chromium GCP

我已经在谷歌云上使用GCP很长时间了,我想运行一个使用Puppeteer的云函数,但不幸的是,我收到以下错误。


未处理的错误错误:找不到 Chromium(修订版 1069273)。如果出现以下任一情况,就会发生这种情况

  1. 您在运行脚本之前没有安装(例如,npm install)或
  2. 您的缓存路径配置不正确(即:/root/.cache/puppeteer)。对于 (2),请查看我们的 Puppeteer 配置指南,网址为https://pptr.dev/guides/configuration。在 ChromeLauncher.resolveExecutablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27) 在 ChromeLauncher.executablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/节点/ChromeLauncher.js:166:25)在ChromeLauncher.launch(/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:70:37)在异步/workspace/lib/index.js :122:21在异步/workspace/node_modules/firebase-functions/lib/common/providers/https.js:407:26

我的代码是


export const test = functions
  .runWith({
    timeoutSeconds: 120,
    memory: "512MB" || "2GB",
  })
  .https.onCall(async (data, context) => {
    const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
    const page = await browser.newPage();
    await page.goto("https://www.google.com/");

    browser.close();
    return { msg: "all good", status: 200 };
  });

Run Code Online (Sandbox Code Playgroud)

我从这里复制了如何在 GCP 功能中使用 Puppeteer 的示例(在我的机器上工作),我还尝试了不使用 Puppeteer 的其他功能,效果很好(所以我确信问题出在 Puppeteer 上)。我还尝试添加标志“--disable-setuid-sandbox”,但这不起作用。我正在用 Typescript 编写 firebase 函数。我的 package.json …

node.js firebase google-cloud-functions puppeteer

16
推荐指数
2
解决办法
5085
查看次数

用于文件上传的Firebase云功能

我有这个云功能,我写的上传文件到谷歌云存储:

const gcs = require('@google-cloud/storage')({keyFilename:'2fe4e3d2bfdc.json'});

var filePath = file.path + "/" + file.name;

    return bucket.upload(filePath, {
        destination: file.name
    }).catch(reason => {
            console.error(reason);
    });
Run Code Online (Sandbox Code Playgroud)

我曾经formidable解析上传的文件,我试图记录上传文件的属性,看起来很好; 它上传到临时目录'/tmp/upload_2866bbe4fdcc5beb30c06ae6c3f6b1aa/但是当我尝试将文件上传到gcs时出现此错误:

{ Error: EACCES: permission denied, stat '/tmp/upload_2866bbe4fdcc5beb30c06ae6c3f6b1aa/thumb_ttttttt.jpg'
    at Error (native)
  errno: -13,
  code: 'EACCES',
  syscall: 'stat',
  path: '/tmp/upload_2866bbe4fdcc5beb30c06ae6c3f6b1aa/thumb_ttttttt.jpg' }
Run Code Online (Sandbox Code Playgroud)

我使用这个html表单上传文件:

<!DOCTYPE html>
<html>
<body>

<form action="https://us-central1-appname.cloudfunctions.net/uploadFile" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript google-cloud-storage firebase google-cloud-functions

15
推荐指数
1
解决办法
1万
查看次数

Firebase 函数本地“文件:”依赖项

我正在使用react-crud-shared作为使用Firebase Cloud Functions 的react-crud-backend 的依赖项。

react-crud-backend我有以下内容:

{
  "name": "react-crud-backend",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    ...
  },
  "dependencies": {
    ...
    "react-crud-shared": "file:../shared",
    ...
  },
  "engines": {
    "node": "8"
  },
  "private": true,
  "devDependencies": {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

react-crud-shared我有以下内容:

{
  "name": "react-crud-shared",
  "version": "0.0.1",
  "description": "",
  "main": "src/index.js",
  "private": true,
  "dependencies": {
    "lodash": "^4.17.11"
  }
}
Run Code Online (Sandbox Code Playgroud)

它在开发中运行良好:“firebase serve --only functions”,但在部署时会引发错误:

Did you list all required modules in the package.json dependencies?
Detailed stack …
Run Code Online (Sandbox Code Playgroud)

npm firebase google-cloud-functions

15
推荐指数
1
解决办法
2978
查看次数