Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 840
Pratap Vhatkar Avatar asked Sep 05 '25 16:09

Pratap Vhatkar


2 Answers

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.

like image 66
Renaud Tarnec Avatar answered Sep 07 '25 18:09

Renaud Tarnec


If your content is already uploaded to a Cloud Storage bucket, there isn't any sort of Cloud Function or simple code to deploy that will do all this automatically. Cloud Functions only respond to events that happen within a bucket, such as the creation or deletion of objects.

What you'll end up having to do is writing some code to list all your objects, then for each one, download it, modify it locally, then upload the modified version back to the bucket. It could be lengthy, depending on on how much content you have. If you just want to do this a single time, you're best off just writing a script and running it in Cloud Shell, so you'll minimize the amount of time spent transferring the objects.

like image 34
Doug Stevenson Avatar answered Sep 07 '25 18:09

Doug Stevenson