0

I wrote a trigger function, when triggered, it will delete a file from storage with a certain name. Problem is here, I do not know the extension of the file. It could be either .png or .jpeg. I tried to write some code to delete the image without regard to file extension, but It does not work. It throws No such object error.

exports.onUserDeletion = functions.auth.user().onDelete((user) => {

    const userid = user.uid
    const filePath = `user_photo/${userid}.{extension}`
    const file = bucket.file(filePath)

    return file.delete()
})

Is there any way to achieve this? Or any workaround where I perfom this deletion without knowing the extension in beforehand?

1 Answer 1

1

Two options:

  1. Just try both extensions.
  2. Store the name in a database ahead of time so you know it for sure later on.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.