Reputation:
Im using the Resize Images extension in Firebase. Before I had added this extension however I have already uploaded many images, they are in their respective post/ storage bucket and are linked via URL in the realtime database.
Is there any way that I can resize all the existing images inside their bucket? Preferably without having to re-assign their URLs with their posts?
Upvotes: 6
Views: 2352
Reputation: 83183
If you look at the code of the "Resize Images" extension, you will see that the Cloud Function that underlies the extension is triggered by a onFinalize
event, which means:
When a new object (or a new generation of an existing object) is successfully created in the bucket. This includes copying or rewriting an existing object.
So, without rewriting/regenerating the existing images the Extension will not be triggered.
However, you could easily write your own Cloud Function that does the same thing but is triggered, for example, by a call to a specific URL (HTTPS cloud Function) or by creating a new document in a temporary Firestore Collection (background triggered CF).
This Cloud Function would execute the following steps:
getFiles()
method of the Google Cloud Storage Node.js Client API. This method returns a GetFilesResponse
object which is an Array of File
instances.Depending on the number of images to treat, you may need to increase the timeout value and/or the allocated memory of your Cloud Function, see https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation
Upvotes: 5