我正在尝试从Firebase云函数访问我的存储
但我不能访问它
它给予我
TypeError:storage.ref不是函数
这是我的代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
var db = admin.firestore();
var storage = admin.storage().bucket();
和我的功能体
exports.deletingVisaCop = functions.firestore.document('users/{user_Id}/info/visa_cop').onUpdate((change,context) =>{
var userId = context.params.user_Id;
// var userRef = db.collection("users").doc(userId).collection("info").doc("visa_cop");
var data = change.after.data().state;
var deleteData = setInterval(function () {
var visaCopStorageRef = storage.ref();
var ref = visaCopStorageRef.child('visa_cop');
ref.delete().then(function(){
console.log("Deleted")
clearTimeout(deleteData);
return true;
}).catch(function(error){
console.log("errorIs" + error)
})
}, 1000);
if(data === true)
{
return deleteData;
} else
{
return clearTimeout(deleteData);
}
});
我想当计时器结束..存储中的节点删除
谢谢你
更新
新错误
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' }
2条答案
按热度按时间cyvaqqii1#
使用
var storage = admin.storage().bucket();
,您将为storage
变量分配默认存储桶,如文档中here所述。正如here的详细说明,
Bucket
没有任何ref()
方法,因此在执行storage.ref();
时会出现错误。如果你想删除bucket,只需使用它的
delete()
方法,如下图所示。如果要删除另一个存储桶,即'visa_cop' bucket,只需如下声明,然后使用
delete()
方法:请注意,我们并不清楚为什么要在Cloud Function中引入“计时器”。功能目标是什么?
bbmckpt72#
您的代码看起来不正确。Firebase文档建议执行以下操作: