We can trigger a cloud function in response to uploading, downloading or deleting files and folders in a storage bucket. To trigger a function for storage changes, developers can make use of functions.storage
to create a function that handles storage events. Based on the use case, we can trigger cloud functions to a specific bucket or to the default bucket:
functions.storage.object()
to listen for object changes on the default storagefunctions.storage.bucket('bucketName').object()
to listen for object changes on a particular bucket
For example, consider the code snippet of the functions:
exports.generateThumbnail = functions.storage.object().onChange((event)=>{ // ... });
Most of the time, developers need not download or upload the files from storage. Sometimes, we might have to generate a thumbnail for the uploaded files. Cloud functions offer an efficient image processing program called ImageMagick that can perform most trivial image processing operations. Consider...