This question has already been answered some places, but none of the solutions worked for me. I also followed the official doc about this. and tried troubleshooting my code for a week, but my code seems correct, only the error keeps appearing that there is not such Object
I noticed that when I used storage triggers for thumb generations for the same image it working, and I compared the file path, bucket name, with the one I'm trying to delete with firestore triggers, there are the same. but only in firestore triggers this is ending in error No such Object
Here is my code and I don't see what is wrong with it.
'use strict';
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
//var serviceAccount = require("./xproject-cdfdc-firebase-adminsdk-xxxx-xxxxx.json");
/*admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://xproject-cdfdc.firebaseio.com"
});*/
admin.initializeApp();
const db = admin.firestore();
const storage = admin.storage();
exports.cleanStorage = functions.firestore.document('items/{itemId}').onDelete((snapshot,context) => {
const id = snapshot.get('itemId');
//log: gettig id successfully
const imageName = snapshot.get('imageName');
//log: getting image name successfully
const defaultBucket = storage.bucket();
//log: defaultBucket.name() => xproject-cdfdc.appspot.com
//log: My bucket is initialzed successfully and exists:
const imageFile = defaultBucket.file('images/'+id+'/'+imageName);
//log: imageFile.name() =>images/W0qMLHqfQANfMsbUEmihK49NFgm2_1595320646264/photo1595320646264.jpg
//log: this path is correct and the file exists on stoarage
return imageFile.delete().then(result =>{
return console.log(`Deleted ${imageName}`);
}).catch(error => {
return console.log("Deliting failed: error->"+error);
//log: error->Error: No such object: xproject-cdfdc.appspot.com/images/W0qMLHqfQANfMsbUEmihK49NFgm2_1595320646264/photo1595320646264.jpg
});
});
So now I don't know what I should correct in my code as in stackoverflow all similar questions have similar solution I've already tried. Any help will be appreciated. thank you.