user12002919
user12002919

Reputation: 35

Firebase Cloud functions: manipulate image before sending to the user

I would like to write a cloud firebase function capable of triggering when a user requests a specific image and before sending it to him modify it by applying a graphic filter. I don't want that filter is applied on the client side.

Upvotes: 1

Views: 266

Answers (2)

LeadDreamer
LeadDreamer

Reputation: 3499

I would strongly suggest you have a trigger that fires when the raw/original image is first saved, and use a Cloud Function to make your modifications and then store that result for the user to call directly. Cold starts are always a possible issue with Cloud Functions, and even without that you would be adding another layer of latency into the user experience.

Note this works even with "live" isochronous code - when the user uploads the "original", trigger/call the cloud function to generate the filtered version. This will overlap at least somewhat with the user interactions (especially if they have a few choices to make), possibly making the app feel more responsive.

Upvotes: 2

MauriceNino
MauriceNino

Reputation: 6747

You would have to write a cloud function for that and call that instead of accessing the bucket directly. There is no way to interfere with the request directly to a bucket.

I have found a basic tutorial to send an image from a cloud function here, but I don't know if that completely fits your needs, so you might have to look for more elaborate tutorials.

To modify the image there are some JS libraries out there, I suggest you look into one of them. One of them is already included into cloud functions as it seems

Upvotes: 2

Related Questions