0

I have the default firebase resize extension installed. It's working perfectly but I realized I do not want the resize to proceed if the image is small, say 20Kb or less than 450Kb. I have edited the function source code to

logs.imageSize("Image Size in bytes: "+size);
    let sizeInMB = parseFloat((size / (1024 * 1024)).toFixed(2));
    logs.imageSize("Image Size in Mb: "+sizeInMB);
    if(sizeInMB<=0.44){
        // The image is 450KB do not compress
        logs.imageIsSmall();
        return;
    }

it should return if the image is 450Kb or less than. Only this block of code is not running. The default resize still proceeds when a new object is added. The above logs also are not shown. What am i missing since, the above code is deployed and is currently on the source code

Taio
  • 3,152
  • 11
  • 35
  • 59
  • Update: Actually this works, but it takes time for changes to kick in. About 30mins for me – Taio Nov 18 '22 at 10:47
  • Another update: once you update the extension, all custom code is deleted. Hope they fix this – Taio Feb 01 '23 at 10:30

1 Answers1

1

I think you need to be more detailed with the situation, I think it might be your conditional if statement might be not valid, have you check and debug the result / value ?

In order to debug an extension, you can use Firebase Emulator Suite, with a setup of Local Storage, Cloud Function and Extensions. with this you can try your extension on the local, without even deploy it. you can check video here : https://www.youtube.com/watch?v=YhKygunUkdw&t=159s

But here i got some tips :

  1. Setup extensions to watch /images directory to listen if the extension should do its job, and output path /thumbnails
  2. you can check the size of the image in the frontend
  3. if it is small upload it into /thumbnails, so it will not run the extension
  4. if it is big, upload it into /images, which will run the extension With this you can always refer to /thumbnails for small images

Firebase Emulator Suite https://firebase.google.com/docs/emulator-suite