【发布时间】:2017-10-09 03:06:27
【问题描述】:
当您通过 Firebase Cloud Functions 删除文件(特别是本例中的照片)时,一些文件会被很好地删除,而一些文件仍会保留在 Firebase 存储中。当文件没有被删除时,我在日志中得到一个错误,错误的文本。
Error: read ECONNRESET at exports._errnoException (util.js:1026:11) at TCP.onread (net.js:569:26)
Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TCP.onread (net.js:569:26)
我的代码
var functions = require('firebase-functions');
const admin = require('firebase-admin');
const gcs = require('@google-cloud/storage')();
admin.initializeApp(functions.config().firebase);
// deleting functions
exports.userDidDeleted = functions.auth.user().onDelete(event => {
const user = event.data; // The Firebase user.
const email = user.email; // The email of the user.
const displayName = user.displayName; // The display name of the user.
const userSearchLocationModelPath = '/userSearchLocationModel/' + user.uid;
console.log('userDidDeleted', userSearchLocationModelPath);
admin.database().ref(userSearchLocationModelPath).remove();
// cards
var cardsRef = admin.database().ref('cards')
cardsRef.orderByChild('ownerID').equalTo(user.uid).on("child_added", function(snapshot) {
console.log('cardsRef', snapshot.key, snapshot.val);
const cardRef = '/cards/' + snapshot.key;
admin.database().ref(cardRef).remove();
// location
admin.database().ref('cardLocation').child(snapshot.key).remove();
// photo
const filePath = 'cardImages/' + snapshot.key + '/mainCardPhoto/' + 'main.jpg';
const bucket = gcs.bucket('example-example7.appspot.com');
const file = bucket.file(filePath);
const pr = file.delete();
});
});
【问题讨论】:
-
ECONNRESET 表示您没有返回承诺。通过返回您的承诺,该函数将等待清理,直到所有工作完成。这里有几件事要检查以了解更多信息:firebase.google.com/docs/functions/terminate-functionsyoutube.com/watch?v=NgZIb6Uwpjc&spfreload=5
-
@JenPerson 非常感谢您
标签: ios firebase firebase-storage google-cloud-functions firebase-admin