Cloud Functions: Resized images not loading

Solution 1:

I just had the same problem, for unknown reason Firebase's Resize Images on purposely remove the download token from the resized image

to disable deleting Download Access Tokens

  • goto https://console.cloud.google.com
  • select Cloud Functions from the left
  • select ext-storage-resize-images-generateResizedImage
  • Click EDIT
  • from Inline Editor goto file FUNCTIONS/LIB/INDEX.JS
  • Add // before this line (delete metadata.metadata.firebaseStorageDownloadTokens;)
  • Comment the same line from this file too FUNCTIONS/SRC/INDEX.TS
  • Press DEPLOY and wait until it finish

note: both original and resized will have the same Token.

Solution 2:

I just started using the extension myself. I noticed that I can't access the image preview from the firebase console until I click on "create access token" I guess that you have to create this token programatically before the image is available.

I hope it helps

Solution 3:

November 2020

In connection to @Somebody answer, I can't seem to find ext-storage-resize-images-generateResizedImage in GCP Cloud Functions

The better way to do it, is to reuse the original file's firebaseStorageDownloadTokens

this is how I did mine

functions
    .storage
    .object()
    .onFinalize((object) => {

      // some image optimization code here
      // get the original file access token
      const downloadtoken = object.metadata?.firebaseStorageDownloadTokens;
      return bucket.upload(tempLocalFile, {
        destination: file,
          metadata: {
            metadata: {
              optimized: true, // other custom flags
              firebaseStorageDownloadTokens: downloadtoken, // access token
            }
            
      });
    });