I would like to achieve the following, but I am currently stuck because the API docs are just too hard. I would like some guidance.
Create a thumbnail image, resizing the image to a width of 100px.
Here are the details to what should be done.
- The thumbnail image should be created whenever a new document is created in Firestore Database.
- The document contains a permanent url of the image stored in Firebase Cloud Storage. (This url was generated via
getDownloadUrl()
method in the flutter cloud storage package.) - The generated thumbnail should be stored to the same directory as the original image.
- The url of the thumbnail image should be updated to the Firestore Database document field.
I am currently using TS but replies in JS would be fine also.
Here is the code that shows my current progress.
const firestore = admin.firestore();
export const generateThumbnailOnCreate = functions
.firestore.document("missions/{missionId}")
.onCreate(async (snap, context) => {
const doc = snap.data();
const missionImgUrl = doc.mission_img_url;
/*
* TODO
* use the mission img url to access the cloud storage
* create thumbnail at the storage directory
* get the permanent thumbnail url update firestore document
*/
return snap.ref
.update({ thumbnail_img_url: thumbnailImgUrl })
.then((docRef) => console.log("Success"))
.catch((err) => console.error("Error"));
});