Function takes too long to execute and returns 504 error code

The code is pretty simple, it’s just a function that uploads a base64 image to Firebase Storage.

exports = async function uploadImageToFirebase(base64, path) {
  const storage = context.functions.execute("initializeFirebase").storage;
  storage.ref(path).putString(base64, 'base64')

The initializeFirebase function does exactly what its name suggests. The code runs fine and the image is successfully uploaded, but after some time (I think 300s, as this is the time constraint of functions) I receive a 504 error.

What can I do in this case? Am I missing something?