【问题标题】:how to get service-account.json to get signedURL in Firebase?如何在 Firebase 中获取 service-account.json 以获取 signedURL?
【发布时间】:2019-02-16 12:17:33
【问题描述】:

我尝试在这里Get Download URL from file uploaded with Cloud Functions for Firebase 中遵循答案。获取存储在 Firebase 存储中的图片的下载 URL

但我需要在为下面的代码初始化gcs 时获取 service-account.json keyFilename

const gcs = require('@google-cloud/storage')({keyFilename: 'service-account.json'})

我不知道如何正确设置{keyFilename: 'service-account.json'}。但这是我所做的:

  1. 首先,我从这里生成私钥并将其命名为 service-account.json https://console.firebase.google.com/project/yourprojectID/settings/serviceaccounts/adminsdk ,service-account.json 包含如下信息:

    { “类型”:“服务帐户”, "project_id": "", “private_key_id”:“”, "private_key": , "client_email": "", “client_id”:“”, “auth_uri”:“”, "token_uri": "", “auth_provider_x509_cert_url”:“”, “client_x509_cert_url”:“” }

  2. 然后将文件放到function文件夹中,如下图使用:

但我从云功能日志中得到错误:

{ Error: ENOENT: no such file or directory, open '../service-account.json'
    at Error (native)
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '../service-account.json' }

gcs 实际上是用来生成缩略图 whenevet 我使用这里的代码将图像上传到存储:https://github.com/firebase/functions-samples/blob/master/quickstarts/thumbnails/functions/index.js

【问题讨论】:

  • 请编辑您的问题以解释您所观察到的表明您没有正确设置的内容。运行代码时是否有错误提示?
  • 非常感谢@DougStevenson,我已经编辑了这个问题。
  • 天哪,新手的错误,应该是 ./service-account.json 而不是 ../service-account.json 。结案
  • 请随意回答您自己的问题,并在经过足够的时间让 SO 允许后将其标记为已接受。
  • 你好阿贡。这张图的环境是什么?我应该将 service-account.json 放在 src 文件夹中,链接在这里:github.com/android/play-billing-samples/tree/master/… 如果你能告诉我我应该做什么,我将不胜感激。哪个软件?或者我应该如何处理链接中的这些文件。

标签: node.js firebase google-cloud-storage google-cloud-functions firebase-storage


【解决方案1】:

新手错误,应该是./service-account.json 而不是../service-account.json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多