Search code examples
firebaseimagegoogle-cloud-platformgoogle-cloud-storageimage-resizing

Resize all images stored in Firebase Storage


I have uploaded around 10k high-resolution images on Firebase Storage Bucket. As of now due high bandwidth I need to scale down those images from the bucket without deleting the original image.

Firebase image resizes extensions function solves this problem but only for those images which have been uploaded newly It will not work for the images which have been already uploaded.

So, Is there any way to do this. I am aware that we use cloud functions to resize the images but I am not sure how will I achieve this, cause there is no trigger for the cloud functions to work.


Solution

  • There is an official Cloud Function sample which shows how to resize images (it is actually quite similar to the Cloud Function that underlies the Resize Images extension).

    This sample Cloud Function triggers on upload of a file to the Firebase project's default Cloud Storage bucket, but it should be easy to adapt its trigger.

    You could, for example, write a callable Cloud Function that uses the Node.js Admin SDK getFiles() method to list all the files of your bucket and resize each file.

    Since you have a lot of files to treat, you should most probably work by batch, since there is a limit of 9 minutes for Cloud Function execution.