tonnoz
tonnoz

Reputation: 502

Avoid re-generating token when using Firebase Image Resize Extension

I am using Firebase resize extension successfully to generate thumbnails while deleting the original picture but once the extension is triggered, the original static token is re-newed for the new resized picture. In order to read the thumbnail I need to run a new ref.getDownloadURL() which I would really like to avoid (extra complication + extra cost). Is there a way to tell the extension (or the underneath function) to keep the old token (metadata) ? Most answers on s.o. seems to refer to older version of the extension or solve a partially similar issue but not this one.

Upvotes: 0

Views: 641

Answers (2)

tonnoz
tonnoz

Reputation: 502

I ended up changing the code of the Image Resize Extension function as suggested by Frank van Puffelen:

  1. Enable The Image Resize Extension as per usual
  2. Go to your Cloud function tab, click on the ext-storage-resize-images-generateResizedImage and from the 3 dots on the right select Detailed Usage Stats
  3. This will bring you to Google Cloud console
  4. From here browse to the lib/resize-image.js file and remove lines 110..112 or add a comment for the whole line 111
  5. Save and re-deploy the cloud function
  6. Enjoy your resized images with the old UUID 😊

Upvotes: 1

Frank van Puffelen
Frank van Puffelen

Reputation: 599946

Since a new file is written by the extension, there is no built-in way to keep the old token. It was an explicit decision to not reuse the existing token, so you might want to read up on that here.

What you can do is to set the old token in the metadata/metadata/firebaseStorageDownloadTokens property yourself as shown here. The Extension pretty much does the same here, but it always generates a new token. If you want to keep the old token, you will have to do this in code, or modify the extension yourself.

Upvotes: 1

Related Questions