byron
byron

Reputation: 994

Firebase Resize Images extension. What does it mean to "Make resized images public"?

I'm using the Firebase Resize Images extension to create 120x120 thumbnails for content, keeping the original images. I was hoping to be able to just store the original full size downloadUrl on my content and do a downloadUrl.replace('.png', '_120x120.png') whenever I want to display a thumbnail. Who wants to store 2 different image urls on every piece of content?

So, I configured the extension to "Make resized images public", but the resized images still require a token and it's a different token from the original image, so I can't just get the thumbnail by adding the size params to the original downloadUrl. If I do, I get a 403 since the tokens are different.

If resized images still require a token, I'm not sure what it means to "Make resized images public". Any guidance? This seems like it would be a pretty common use case, so maybe I'm missing something.

Upvotes: 0

Views: 1148

Answers (2)

byron
byron

Reputation: 994

Another solution is to modify the source code of the extension to disable the generation of a new token. Similar process described here: Avoid re-generating token when using Firebase Image Resize Extension, but line numbers are updated for Dec '22

  1. Go to Firebase / Cloud Functions
  2. Find the ext-storage-resize-images-generateResizedImage function
  3. Click on the three dots at the right and open Detailed Usage Stats
  4. Once in the GCP console, click EDIT, then click NEXT at the bottom left (easy to miss)
  5. Navigate to /lib/resize-image.js
  6. Find the following (lines 143-145 in Dec `22):
if (metadata.metadata.firebaseStorageDownloadTokens) {
  metadata.metadata.firebaseStorageDownloadTokens = uuidv4_1.uuid();
}
  1. Comment out the whole if statement, or just the internal. This will prevent the extension from generating a new token for the resized image, and instead use the same token as the original.
if (metadata.metadata.firebaseStorageDownloadTokens) {
  // metadata.metadata.firebaseStorageDownloadTokens = uuidv4_1.uuid();
}
  1. Save and redeploy the function. It usually takes a few minutes, but it works. Resized images will have the same token as the originals.

NOTE: If you modify the Resize Images extension configuration in the Firebase Console after doing this, it will overwrite your changes, so you'll need to follow this process again.

Upvotes: 0

samthecodingman
samthecodingman

Reputation: 26296

Making a file public allows you to skip using download URLs, which are signed with access tokens that expire.

Instead, you can access files using their public URI, which is of the format:

https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME

So for one of your thumbnails, you use something similar to the following URI:

https://storage.googleapis.com/my-project-id.appspot.com/userImages/NT672kMZu5c1kijkAmsoqRUDivC3/profile_120x120.png

Upvotes: 2

Related Questions