【问题标题】:Firebase functions :ApiError: Not Found at Object.parseHttpRespBod : when removing from firebase storageFirebase 函数:ApiError: Not Found at Object.parseHttpRespBod :从 Firebase 存储中删除时
【发布时间】:2019-06-12 19:31:36
【问题描述】:

我正在尝试通过 firebase 云功能从我的 firebase 存储中删除一个项目。

但它给了我这个错误..

    Error { ApiError: Not Found
    at Object.parseHttpRespBody (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/common/src/util.js:193:30)
    at Object.handleResp (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/common/src/util.js:131:18)
    at /user_code/node_modules/firebase-admin/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/common/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/user_code/node_modules/firebase-admin/node_modules/request/request.js:185:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/user_code/node_modules/firebase-admin/node_modules/request/request.js:1161:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
  code: 404,
  errors: [ { domain: 'global', reason: 'notFound', message: 'Not Found' } ],
  response: undefined,
  message: 'Not Found' }

这是我的代码:

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

admin.initializeApp();
var db = admin.firestore();


var storage = admin.storage().bucket('visa_cop');


exports.deletingVisaCop = functions.firestore.document('users/{user_Id}/info/visa_cop').onUpdate((change,context) =>{
    var data = change.after.data().checked;

    if(data === true)
    {
        return storage.delete().then(function(data) {
            return console.log("DataIs",data);
          }).catch(function(error){
             return console.log("Error",error);  
          });
    } else
    {
    }
});

我从“我是和管理员”页面添加了 Google API 服务代理和 App Engine 默认服务帐户存储管理员角色。

谢谢。

【问题讨论】:

  • 您似乎正在尝试删除名为“visa_cop”的整个存储桶。那是你要的吗?你到底想在这里完成什么?
  • 我只是尝试如果它成功然后我会稍后调整它..但我想检查它是否会被删除..所以是的我想删除所有它
  • 在这种情况下,错误消息告诉您找不到具有您给定名称的存储桶。我会说,在 Cloud Function 中以编程方式创建和删除存储桶可能不是您真正想要做的。
  • 我只是按照文档.. 我有这个带有它的名字的存储桶.. 那么问题是什么

标签: firebase google-cloud-platform google-cloud-functions firebase-storage


【解决方案1】:

问题出在这里:

functions.firestore.document('users/{user_Id}/info/visa_cop').onUpdate((change,context)

目前,该函数侦听文件夹“info”中名为“visa_cop”的文档。您需要在末尾添加令牌,以告诉函数侦听此文件夹中任何文件的更新(或者您可以根据需要指定文件)。

只需附加例如/{visaId}visa_cop 之后,像这样:

functions.firestore.document('users/{user_Id}/info/visa_cop/{visaId}').onUpdate((change,context)

附言。 “visaId”可以是任何东西,但它必须与您在函数部署时定义的文档路径匹配。

在您的示例中,该函数侦听“visa_cop”文件夹中的任何文档,因此如果您使用:

控制台:

  • 触发器是“Cloud Firestore”
  • 事件类型是“更新”
  • 文档路径为“students/{studentId}/visa_cop/{visaId}”

命令行界面:

gcloud functions deploy [FUNCTION_NAME] \
--runtime [RUNTIME] \
--trigger-event providers/cloud.firestore/eventTypes/document.update \
--trigger-resource "projects/[PROJECT_ID]/databases/(default)/documents/users/{userId}/info/visa_cop/{visaId}"

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2020-12-29
    • 2014-07-01
    • 2021-07-07
    • 2017-10-05
    • 2019-12-20
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多