Firebase:使用云功能删除Cloud Starage中的文件

时间:2017-12-05 19:15:09

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

我正在尝试使用Realtime Database删除条目删除时Cloud Storage中与Cloud Functions中某些特定条目相关的所有文件。我的功能看起来像休闲:

exports.onDeleteRequest = functions.database.ref('/requests/{requestid}/').onDelete(event => {
    const storage = functions.config().firebase.storageBucket;
    const userId = event.data.previous.child('uid').val();
    const requestId = event.params.requestid;
    const path = storage + '/photos/' + userId + '/' + requestId;
    console.log('path: ', path);
    return gcs.bucket(path).delete().then(function() {
            console.log("Files removed");
        }).catch(function(error) {
            console.error("Failed removing files", error);
        });
});

但是,我在日志中继续收到以下错误:

Failed removing files { ApiError: Not Found
    at Object.parseHttpRespBody (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:192:30)
    at Object.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:132:18)
    at /user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:465:12
    at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:182:7)
    at Request.self.callback (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:1163: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' }

path: photos/gRplE2ujnIb93Ji5HSzEj3O4i3d2/-L-DHkKMhvLH9l6dWmR2

在执行功能时,所有子文件夹都是100%存在的。有人可以帮忙吗?

我为提出这个问题而道歉,毫无疑问,之前曾以某种方式询问过这个问题,但我没有找到任何关于如何解决这个问题的建议,或者为什么它首先出现。

0 个答案:

没有答案