google-cloud-functionsgoogle-cloud-storagefirebase-extensions

Firebase resize extension fails time to time on multiple images


I have the Firebase resize extension and it works correctly. only when multiple images are uploaded concurrently some of them fail to load after resizing. I get 404 on about 3/10 which is frustrating since we now have to track on the frontend when an image fails to load and delete it for the user to reupload it. Is there a solution to this or a workaround like maybe retry resize or something. The default behavior of the user is to select multiple files at a go and upload them and this cannot be changed.


Solution

  • In the end I ended up with this solution

    const url=`https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/${encodeURIComponent(
              event.data.outputs[0].outputFilePath,
          )}?alt=media&token=${metadata[0].metadata.firebaseStorageDownloadTokens}`;
    

    This is the only way I found to get a url similar and consistent to the one in firebase console. Similar to the one gotten from getDownloadURL on the client

    The previous solutions had been getting signedUrls, failed to work for my use case as they expire after some period. The other solution when posting this question was

    const file = storage.bucket(firebaseConfig.storageBucket)
          .file(event.data.outputs[0].outputFilePath);
    
      const metadata = await file.getMetadata();
      const url = metadata[0].mediaLink;
    

    This gave a url starting with storage.googleapis and sometimes a firebase similar url, only these image urls failed to load with a 404 error 3/10 times on the frontend.

    This article has been a great help in fixing this url issues for a while and I got the solution there as well.

    Sidenote: Also I had thought the function was getting several multiple requests at a go and was unable to handle the requests so I scaled up the minInstances and the memory too. This again was not the issue, and I have removed the minInstances and reduced the memory to 1Gib