title
Firebase Cloud Functions - Creating a REST Endpoint with Cloud Functions

description
Firebase is a serverless service that allows you to run your (mobile) app backend with zero effort. A very useful use-case is that you can create REST API Endpoints with Cloud Functions. On-demand, serverless code targeted via REST requests - a dream coming true! ---------- This video also has an accompanying article: https://www.academind.com/learn/firebase/cloud-functions/creating-a-rest-endpoint-with-cloud-functions Source Code: https://github.com/academind/firebase-cloud-functions-introduction/tree/02-http More on Cloud Functions: https://firebase.google.com/docs/functions/ ---------- • You can follow Max on Twitter (@maxedapps). • And you should of course also follow @academind_real. • You can also find us on Facebook.(https://www.facebook.com/academindchannel/) • Or visit our Website (https://www.academind.com) and subscribe to our newsletter! See you in the videos!

detail
{'title': 'Firebase Cloud Functions - Creating a REST Endpoint with Cloud Functions', 'heatmap': [{'end': 165.517, 'start': 142.58, 'weight': 0.851}, {'end': 355.983, 'start': 330.295, 'weight': 0.704}, {'end': 382.025, 'start': 359.764, 'weight': 0.824}, {'end': 499.206, 'start': 463.17, 'weight': 0.792}, {'end': 710.921, 'start': 692.705, 'weight': 0.754}, {'end': 1109.826, 'start': 1071.466, 'weight': 1}, {'end': 1177.049, 'start': 1129.803, 'weight': 0.783}, {'end': 1336.232, 'start': 1318.407, 'weight': 0.718}], 'summary': 'Covers creating http cloud functions in firebase, deploying and testing for http events, handling http verbs, leveraging node express syntax and packages, enabling cross-origin resource sharing for cloud storage, using busboy to parse and store files, uploading files to firebase cloud storage, setting up google cloud storage in firebase, and setting up http endpoints for file uploads.', 'chapters': [{'end': 142.299, 'segs': [{'end': 32.119, 'src': 'embed', 'start': 2.426, 'weight': 0, 'content': [{'end': 3.267, 'text': 'Welcome to this video.', 'start': 2.426, 'duration': 0.841}, {'end': 5.048, 'text': 'Great to see you back in this mini-series.', 'start': 3.287, 'duration': 1.761}, {'end': 13.074, 'text': 'In the last videos, we learned what Firebase Cloud Functions are and how to create a Cloud Function that listens to changes in our Firebase storage.', 'start': 5.488, 'duration': 7.586}, {'end': 19.139, 'text': "In this video, we'll listen to HTTP events, hence actually creating our own API.", 'start': 13.475, 'duration': 5.664}, {'end': 20.3, 'text': "Let's dive into that.", 'start': 19.459, 'duration': 0.841}, {'end': 26.875, 'text': "So let's add a new Cloud Function.", 'start': 24.793, 'duration': 2.082}, {'end': 32.119, 'text': "Here's the Cloud Function I created in the last video, the one which reacts on storage events.", 'start': 27.255, 'duration': 4.864}], 'summary': 'Creating an api using cloud functions for firebase.', 'duration': 29.693, 'max_score': 2.426, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE2426.jpg'}, {'end': 98.2, 'src': 'embed', 'start': 68.75, 'weight': 2, 'content': [{'end': 78.397, 'text': 'This object here actually will hold a request and a response object, as you know it from express apps, node express.', 'start': 68.75, 'duration': 9.647}, {'end': 81.2, 'text': 'So in there we can now do something.', 'start': 79.198, 'duration': 2.002}, {'end': 83.121, 'text': 'We should absolutely send a response.', 'start': 81.32, 'duration': 1.801}, {'end': 84.102, 'text': "That's the bare minimum.", 'start': 83.161, 'duration': 0.941}, {'end': 93.489, 'text': 'So what we can do here is we can send a status code of 200 with maybe some JSON data where we output a message.', 'start': 84.562, 'duration': 8.927}, {'end': 98.2, 'text': 'it worked and you could also send html here.', 'start': 95.496, 'duration': 2.704}], 'summary': 'Node express can send a response with status code 200 and json data.', 'duration': 29.45, 'max_score': 68.75, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE68750.jpg'}, {'end': 142.299, 'src': 'embed', 'start': 120.901, 'weight': 1, 'content': [{'end': 133.446, 'text': 'so let me run firebase deploy in our project here to put this back into firebase and create a function with this upload file uh function we just defined,', 'start': 120.901, 'duration': 12.545}, {'end': 136.735, 'text': "and then let's see how we can trigger that Deployment finished.", 'start': 133.446, 'duration': 3.289}, {'end': 142.299, 'text': 'And now if you expand the console here or scroll up, you will see where your functions are deployed to.', 'start': 136.975, 'duration': 5.324}], 'summary': 'Running firebase deploy to put project back into firebase and create a function, triggering deployment finished.', 'duration': 21.398, 'max_score': 120.901, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE120901.jpg'}], 'start': 2.426, 'title': 'Creating http cloud functions', 'summary': 'Discusses creation of http cloud functions in firebase, covering listening to http events, api creation, and deploying the function using firebase.', 'chapters': [{'end': 142.299, 'start': 2.426, 'title': 'Creating http cloud functions', 'summary': 'Discusses creating an http cloud function in firebase, demonstrating how to listen to http events and create an api, along with deploying the function using firebase.', 'duration': 139.873, 'highlights': ['The chapter demonstrates creating an HTTP Cloud Function in Firebase to listen to HTTP events and create an API, showcasing the process of exporting a new function, using the functions object from the firebase functions package, and defining on request function for executing HTTP requests.', "The video explains the process of deploying the created HTTP Cloud Function using Firebase, emphasizing the use of 'firebase deploy' command to put the function back into Firebase and create a function with the defined upload file function.", 'The speaker highlights the importance of sending a response from the HTTP Cloud Function, emphasizing the usage of status code 200 and sending JSON or HTML data as a response to the HTTP request.']}], 'duration': 139.873, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE2426.jpg', 'highlights': ['The chapter demonstrates creating an HTTP Cloud Function in Firebase to listen to HTTP events and create an API, showcasing the process of exporting a new function, using the functions object from the firebase functions package, and defining on request function for executing HTTP requests.', "The video explains the process of deploying the created HTTP Cloud Function using Firebase, emphasizing the use of 'firebase deploy' command to put the function back into Firebase and create a function with the defined upload file function.", 'The speaker highlights the importance of sending a response from the HTTP Cloud Function, emphasizing the usage of status code 200 and sending JSON or HTML data as a response to the HTTP request.']}, {'end': 513.397, 'segs': [{'end': 190.815, 'src': 'heatmap', 'start': 142.58, 'weight': 1, 'content': [{'end': 147.183, 'text': "And for HTTPS functions, you'll get the endpoint you have to send a request to.", 'start': 142.58, 'duration': 4.603}, {'end': 151.247, 'text': "So I'll copy that URL here and then I'll simply open Postman.", 'start': 147.444, 'duration': 3.803}, {'end': 158.692, 'text': 'That is a tool that allows you to send HTTP requests, well, to any endpoint you want, essentially.', 'start': 152.267, 'duration': 6.425}, {'end': 165.517, 'text': "In there, I'll enter the URL, and I won't set any special headers or a body.", 'start': 159.272, 'duration': 6.245}, {'end': 167.658, 'text': "I'll just send a GET request, and it's sent.", 'start': 165.597, 'duration': 2.061}, {'end': 174.083, 'text': 'and now this gives me indeed back some json data it worked with status code 200.', 'start': 168.619, 'duration': 5.464}, {'end': 178.846, 'text': 'so this shows, does it, that it works and we can also send a post request to this endpoint.', 'start': 174.083, 'duration': 4.763}, {'end': 180.848, 'text': 'we get back to the same response.', 'start': 178.846, 'duration': 2.002}, {'end': 187.552, 'text': 'if we only want to handle some http verbs and not all of them, we have to do this in this endpoint.', 'start': 180.848, 'duration': 6.704}, {'end': 190.815, 'text': 'by default, it handles all incoming requests.', 'start': 187.552, 'duration': 3.263}], 'summary': 'Using postman to send http requests, receiving json data with status code 200.', 'duration': 48.235, 'max_score': 142.58, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE142580.jpg'}, {'end': 247.823, 'src': 'embed', 'start': 219.091, 'weight': 0, 'content': [{'end': 225.153, 'text': "And as you already see, I'm using the same syntax you use in a normal Node Express project,", 'start': 219.091, 'duration': 6.062}, {'end': 231.154, 'text': 'because Firebase Cloud Functions for HTTP events use Node Express behind the scenes.', 'start': 225.153, 'duration': 6.001}, {'end': 235.535, 'text': 'So you can use the same syntax and the same packages for Node Express project.', 'start': 231.174, 'duration': 4.361}, {'end': 236.295, 'text': "So that's pretty cool.", 'start': 235.555, 'duration': 0.74}, {'end': 238.056, 'text': 'so this is something to keep in mind.', 'start': 236.875, 'duration': 1.181}, {'end': 247.823, 'text': 'you can really build your node express project in a restful way and on a per endpoint basis with cloud functions.', 'start': 238.056, 'duration': 9.767}], 'summary': 'Firebase cloud functions for http events use node express, allowing restful node express project building.', 'duration': 28.732, 'max_score': 219.091, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE219091.jpg'}, {'end': 382.025, 'src': 'heatmap', 'start': 330.295, 'weight': 3, 'content': [{'end': 334.998, 'text': 'even though your web app might not be running on the same origin, not on the same server.', 'start': 330.295, 'duration': 4.703}, {'end': 336.558, 'text': 'So I want to allow that.', 'start': 335.518, 'duration': 1.04}, {'end': 339.179, 'text': 'And for that, I will install a new package.', 'start': 336.878, 'duration': 2.301}, {'end': 341.34, 'text': 'So navigate into the functions folder.', 'start': 339.559, 'duration': 1.781}, {'end': 346.661, 'text': "And with npm install dash dash save, I'll install the course package.", 'start': 341.84, 'duration': 4.821}, {'end': 355.983, 'text': 'Now this is a Node Express package we can use to conveniently set some headers we need to send back to the client to allow this cross-origin access.', 'start': 347.661, 'duration': 8.322}, {'end': 359.644, 'text': "And with that installed, I'll import it here.", 'start': 357.464, 'duration': 2.18}, {'end': 362.285, 'text': 'Course Require course.', 'start': 359.764, 'duration': 2.521}, {'end': 373.62, 'text': 'this is executed as a function and i pass an object to that function where i set origin to true, to set up this,', 'start': 364.554, 'duration': 9.066}, {'end': 382.025, 'text': 'uh these course headers for this origin correctly and then i will actually wrap my entire code here with this course middleware.', 'start': 373.62, 'duration': 8.405}], 'summary': 'Installing and using the course package to allow cross-origin access for the web app.', 'duration': 43.325, 'max_score': 330.295, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE330295.jpg'}, {'end': 499.206, 'src': 'heatmap', 'start': 463.17, 'weight': 0.792, 'content': [{'end': 464.351, 'text': 'So we already got this at least.', 'start': 463.17, 'duration': 1.181}, {'end': 473.373, 'text': "Now for parsing that incoming request body, I'll use a package named busboy, which is a package that is able to handle incoming forum data.", 'start': 465.185, 'duration': 8.188}, {'end': 479.399, 'text': 'So again, navigate into the functions folder and run npm install dash dash save busboy like that.', 'start': 474.013, 'duration': 5.386}, {'end': 489.128, 'text': "And then once this is installed, navigate back into the main directory and I'll import busboy from the busboy package.", 'start': 480.7, 'duration': 8.428}, {'end': 499.206, 'text': "like this and then I'll go into my course wrapper and after I checked the method of the request,", 'start': 492.281, 'duration': 6.925}], 'summary': 'Using busboy to handle incoming form data in the functions folder.', 'duration': 36.036, 'max_score': 463.17, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE463170.jpg'}, {'end': 489.128, 'src': 'embed', 'start': 465.185, 'weight': 5, 'content': [{'end': 473.373, 'text': "Now for parsing that incoming request body, I'll use a package named busboy, which is a package that is able to handle incoming forum data.", 'start': 465.185, 'duration': 8.188}, {'end': 479.399, 'text': 'So again, navigate into the functions folder and run npm install dash dash save busboy like that.', 'start': 474.013, 'duration': 5.386}, {'end': 489.128, 'text': "And then once this is installed, navigate back into the main directory and I'll import busboy from the busboy package.", 'start': 480.7, 'duration': 8.428}], 'summary': 'Using busboy package to handle incoming forum data', 'duration': 23.943, 'max_score': 465.185, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE465185.jpg'}], 'start': 142.58, 'title': 'Firebase cloud functions and cross-origin access', 'summary': 'Demonstrates deploying and testing firebase cloud functions for http events, handling http verbs, and leveraging node express syntax and packages. it also covers enabling cross-origin resource sharing for cloud storage, including handling file uploads to firebase storage.', 'chapters': [{'end': 279.473, 'start': 142.58, 'title': 'Firebase cloud functions for http events', 'summary': 'Demonstrates deploying and testing firebase cloud functions for http events using postman, handling http verbs, and leveraging node express syntax and packages, resulting in the ability to build restful node express projects on a per-endpoint basis.', 'duration': 136.893, 'highlights': ['Firebase Cloud Functions use Node Express behind the scenes Firebase Cloud Functions for HTTP events use Node Express behind the scenes, enabling the usage of the same syntax and packages for Node Express projects, providing familiarity and ease of use.', 'Handling HTTP verbs and specifying endpoints Demonstrates the ability to handle specific HTTP verbs for endpoints, such as allowing only POST requests, by checking the request method and returning appropriate responses, ensuring controlled access and functionality.', 'Testing with Postman and deployment process Utilizes Postman for testing the HTTP requests, ensuring successful deployment with status code 200 and showcasing the process of updating and deploying functions while ensuring endpoint stability.']}, {'end': 513.397, 'start': 280.374, 'title': 'Enabling cross-origin access and handling file uploads', 'summary': "Covers enabling cross-origin resource sharing for cloud storage, including installing and using the 'cors' package, and setting up 'busboy' to parse incoming form data for file uploads to firebase storage.", 'duration': 233.023, 'highlights': ["Enabling Cross-Origin Access The chapter discusses enabling cross-origin resource sharing by installing and using the 'cors' package to allow HTTP requests from apps not hosted on the same server, ensuring cross-origin access for cloud storage.", "Setting up 'cors' Package The author explains the process of installing and using the 'cors' package to conveniently set headers needed to allow cross-origin access, by executing it as a middleware function and passing an object with the 'origin' set to 'true'.", "Installing 'busboy' for Handling File Uploads The chapter details the installation and usage of the 'busboy' package to parse incoming form data for handling file uploads, necessary for storing files on Firebase Storage."]}], 'duration': 370.817, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE142580.jpg', 'highlights': ['Firebase Cloud Functions use Node Express behind the scenes, providing familiarity and ease of use.', 'Demonstrates the ability to handle specific HTTP verbs for endpoints, ensuring controlled access and functionality.', 'Utilizes Postman for testing the HTTP requests, ensuring successful deployment and endpoint stability.', "Enabling cross-origin resource sharing by installing and using the 'cors' package.", "Explains the process of setting up the 'cors' package to allow cross-origin access conveniently.", "Details the installation and usage of the 'busboy' package for handling file uploads."]}, {'end': 1051.651, 'segs': [{'end': 536.39, 'src': 'embed', 'start': 513.837, 'weight': 0, 'content': [{'end': 521.864, 'text': 'This is required to, well, allow busboy to find out whether the incoming request is of type form data or not, so if it should parse it or not.', 'start': 513.837, 'duration': 8.027}, {'end': 530.947, 'text': "With that, I'll use this busboy object and add the onListener, and I'll listen to file events.", 'start': 522.984, 'duration': 7.963}, {'end': 536.39, 'text': 'These will be triggered whenever busboy successfully parses a file from the incoming request.', 'start': 531.268, 'duration': 5.122}], 'summary': 'Using busboy to parse incoming form data and listen to file events.', 'duration': 22.553, 'max_score': 513.837, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE513837.jpg'}, {'end': 695.768, 'src': 'embed', 'start': 670.462, 'weight': 2, 'content': [{'end': 676.703, 'text': 'Busboy on simply triggers whenever it found a file, but finish triggers once it is done parsing the entire request.', 'start': 670.462, 'duration': 6.241}, {'end': 679.364, 'text': 'This is when I want to upload the data.', 'start': 677.264, 'duration': 2.1}, {'end': 684.696, 'text': 'So here in this handler function, And I want to use Google Cloud Storage to upload.', 'start': 679.804, 'duration': 4.892}, {'end': 692.184, 'text': "So I'll create a bucket object here and use GCS bucket to do that, to get a reference to that bucket.", 'start': 685.337, 'duration': 6.847}, {'end': 695.768, 'text': 'And now I want to get my default bucket for this Firebase account.', 'start': 692.705, 'duration': 3.063}], 'summary': 'Busboy triggers when file found, finish triggers after parsing. uploading data to google cloud storage using bucket object.', 'duration': 25.306, 'max_score': 670.462, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE670462.jpg'}, {'end': 723.969, 'src': 'heatmap', 'start': 692.705, 'weight': 0.754, 'content': [{'end': 695.768, 'text': 'And now I want to get my default bucket for this Firebase account.', 'start': 692.705, 'duration': 3.063}, {'end': 706.638, 'text': "You can get this easily by visiting your storage, and there it's basically this name, without the gs colon slash slash at the beginning.", 'start': 696.549, 'duration': 10.089}, {'end': 708.399, 'text': "this is what i'll pass here.", 'start': 706.638, 'duration': 1.761}, {'end': 710.921, 'text': 'this is my default bucket.', 'start': 708.399, 'duration': 2.522}, {'end': 714.383, 'text': 'this is the bucket into which i want to store the file.', 'start': 710.921, 'duration': 3.462}, {'end': 723.969, 'text': 'now, with that reference created, i can trigger bucket upload, call that method pass my file, and that is why i got this upload data object here,', 'start': 714.383, 'duration': 9.586}], 'summary': 'Retrieve default bucket from firebase storage for file upload.', 'duration': 31.264, 'max_score': 692.705, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE692705.jpg'}, {'end': 837.557, 'src': 'embed', 'start': 812.676, 'weight': 1, 'content': [{'end': 824.706, 'text': "And let's then see if we can successfully send a form data request with a file in it to our backend here and then store that in Firebase Cloud Storage.", 'start': 812.676, 'duration': 12.03}, {'end': 830.431, 'text': 'And then it should actually also trigger our resize function, which we wrote in the last video.', 'start': 825.086, 'duration': 5.345}, {'end': 832.673, 'text': "So let's see if that both is the case.", 'start': 830.731, 'duration': 1.942}, {'end': 835.415, 'text': 'The deployment is done here.', 'start': 833.814, 'duration': 1.601}, {'end': 837.557, 'text': "Again, don't rush this.", 'start': 835.435, 'duration': 2.122}], 'summary': 'Test form data request with file, trigger resize function, and deploy successfully.', 'duration': 24.881, 'max_score': 812.676, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE812676.jpg'}, {'end': 885.9, 'src': 'embed', 'start': 861.182, 'weight': 7, 'content': [{'end': 867.286, 'text': 'so let me hit send here and i actually get back an error could not handle the request.', 'start': 861.182, 'duration': 6.104}, {'end': 870.709, 'text': "let's have a look at our firebase functions log here.", 'start': 867.286, 'duration': 3.423}, {'end': 876.372, 'text': "so on firebase cloud functions, i'll have a look at my upload file log.", 'start': 870.709, 'duration': 5.663}, {'end': 881.156, 'text': "here and there i can't read headers of undefined at course.", 'start': 876.372, 'duration': 4.784}, {'end': 885.9, 'text': 'um yeah, because i got an error here.', 'start': 882.758, 'duration': 3.142}], 'summary': 'Error encountered while sending request, unable to read headers, and log analysis in firebase cloud functions.', 'duration': 24.718, 'max_score': 861.182, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE861182.jpg'}, {'end': 957.864, 'src': 'embed', 'start': 934.934, 'weight': 5, 'content': [{'end': 945.749, 'text': "so let's try sending this again and now it's taking really really long here And you can see in the log that it started a function execution,", 'start': 934.934, 'duration': 10.815}, {'end': 947.693, 'text': "but somehow it's not finishing here.", 'start': 945.749, 'duration': 1.944}, {'end': 957.864, 'text': "Now, it will time out after 60 seconds, that's the default timeout, so you get no infinite running function costing you thousands of dollars.", 'start': 948.482, 'duration': 9.382}], 'summary': 'Function execution is taking too long, risking high costs.', 'duration': 22.93, 'max_score': 934.934, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE934934.jpg'}, {'end': 1030.531, 'src': 'embed', 'start': 1007.117, 'weight': 6, 'content': [{'end': 1014.58, 'text': 'There, we get the file path, but actually, this is not a file path Busboy will automatically store the file in.', 'start': 1007.117, 'duration': 7.463}, {'end': 1017.681, 'text': "It's a file path we can use to store the file in.", 'start': 1014.92, 'duration': 2.761}, {'end': 1025.665, 'text': "So first of all let's import another dependency, the file system uh package, which is a default node package,", 'start': 1017.981, 'duration': 7.684}, {'end': 1028.548, 'text': "so we don't need to install it separately.", 'start': 1025.665, 'duration': 2.883}, {'end': 1030.531, 'text': 'and then in the file listener.', 'start': 1028.548, 'duration': 1.983}], 'summary': 'Busboy automatically stores files using file path', 'duration': 23.414, 'max_score': 1007.117, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1007117.jpg'}], 'start': 513.837, 'title': 'Using busboy and firebase cloud functions', 'summary': 'Covers using busboy to parse and store files, uploading files to firebase cloud storage, and troubleshooting firebase cloud functions. it explains file detection, storage in firebase storage, triggering functions, setting mime types, handling upload responses, and troubleshooting function errors, deployment, timeout, and file path parsing, including the default 60-second timeout and free tier limit.', 'chapters': [{'end': 591.376, 'start': 513.837, 'title': 'Using busboy to parse and store files', 'summary': 'Explains using the busboy object to parse incoming form data, listening to file events, and executing a function for every file detected in the request. it details the process of detecting and storing files in firebase storage.', 'duration': 77.539, 'highlights': ['Using the Busboy object to parse incoming form data and listen to file events for successful file parsing.', 'Executing a function for every file detected in the request, which provides details such as field name, file, file name, encoding, and MIME type.', 'Storing the detected files in Firebase Storage for future use.']}, {'end': 861.182, 'start': 591.376, 'title': 'Cloud file upload with busboy and google cloud storage', 'summary': 'Covers the process of uploading a file to firebase cloud storage using busboy and google cloud storage, including triggering functions, setting mime types, and handling upload responses.', 'duration': 269.806, 'highlights': ['The process involves using Busboy to access the temporary cloud storage and create a path to the file, then setting up an object to hold the file data, and finally using Google Cloud Storage to upload the file. The process involves accessing the temporary cloud storage and creating a path to the file using Busboy, setting up an object to hold the file data, and using Google Cloud Storage to upload the file.', "The chapter emphasizes the use of Busboy's 'on file' and 'on finish' functions to handle file parsing and trigger the upload process, as well as the importance of setting MIME types for the uploaded file. The chapter emphasizes the use of Busboy's 'on file' and 'on finish' functions to handle file parsing and trigger the upload process, as well as the importance of setting MIME types for the uploaded file.", 'The author describes the process of handling upload responses, including error handling and successful file uploading, while also mentioning triggering the resize function upon successful upload. The author describes the process of handling upload responses, including error handling and successful file uploading, while also mentioning triggering the resize function upon successful upload.']}, {'end': 1051.651, 'start': 861.182, 'title': 'Firebase cloud functions troubleshooting', 'summary': 'Outlines troubleshooting of firebase cloud functions including handling errors, deploying updated functions, and addressing issues related to function timeout and file path parsing, highlighting the default timeout of 60 seconds and the free tier limit for function execution.', 'duration': 190.469, 'highlights': ['The function timed out after 60 seconds, the default timeout, to prevent infinite running functions, and the free tier allows multiple executions before incurring costs.', 'The file path parsing issue is addressed by importing the file system package and utilizing the fs create write stream method to store the file content with the appropriate file path.', "The error 'could not handle the request' was encountered during function execution, leading to troubleshooting steps and deployment of updated functions."]}], 'duration': 537.814, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE513837.jpg', 'highlights': ['Using the Busboy object to parse incoming form data and listen to file events for successful file parsing.', 'Storing the detected files in Firebase Storage for future use.', 'The process involves using Busboy to access the temporary cloud storage and create a path to the file, then setting up an object to hold the file data, and finally using Google Cloud Storage to upload the file.', "The chapter emphasizes the use of Busboy's 'on file' and 'on finish' functions to handle file parsing and trigger the upload process, as well as the importance of setting MIME types for the uploaded file.", 'The author describes the process of handling upload responses, including error handling and successful file uploading, while also mentioning triggering the resize function upon successful upload.', 'The function timed out after 60 seconds, the default timeout, to prevent infinite running functions, and the free tier allows multiple executions before incurring costs.', 'The file path parsing issue is addressed by importing the file system package and utilizing the fs create write stream method to store the file content with the appropriate file path.', "The error 'could not handle the request' was encountered during function execution, leading to troubleshooting steps and deployment of updated functions."]}, {'end': 1445.483, 'segs': [{'end': 1128.562, 'src': 'heatmap', 'start': 1071.466, 'weight': 0, 'content': [{'end': 1077.85, 'text': 'And we can do this easily by going to our Firebase project and then to the settings, project settings, and there to service accounts.', 'start': 1071.466, 'duration': 6.384}, {'end': 1087.177, 'text': 'There, you can now download under Firebase admin SDK, you can download a private key which you need to initialize cloud storage.', 'start': 1078.911, 'duration': 8.266}, {'end': 1094.382, 'text': 'So you can click generate new private key, and then stored it in your project folder.', 'start': 1087.837, 'duration': 6.545}, {'end': 1097.029, 'text': 'So here in the functions folder.', 'start': 1094.402, 'duration': 2.627}, {'end': 1100.837, 'text': 'So now I added this file, which holds my private key.', 'start': 1097.049, 'duration': 3.788}, {'end': 1109.826, 'text': 'And now in your Firebase Cloud Function, you actually need to initialize your Google Cloud Storage a bit differently.', 'start': 1102.301, 'duration': 7.525}, {'end': 1112.927, 'text': 'You need to initialize it such that you can use it in every function.', 'start': 1109.986, 'duration': 2.941}, {'end': 1122.793, 'text': "So I'll put it a bit further down because before we import it I'll add a new constant, which I'll name gcconfig for Google Cloud Config,", 'start': 1113.568, 'duration': 9.225}, {'end': 1126.516, 'text': 'where I will just specify the project ID.', 'start': 1122.793, 'duration': 3.723}, {'end': 1128.562, 'text': 'whoops like that.', 'start': 1127.722, 'duration': 0.84}], 'summary': 'Initialize google cloud storage in firebase cloud function using private key from firebase admin sdk.', 'duration': 49.651, 'max_score': 1071.466, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1071466.jpg'}, {'end': 1177.049, 'src': 'heatmap', 'start': 1129.803, 'weight': 0.783, 'content': [{'end': 1134.104, 'text': 'project id, which is just your firebase project id.', 'start': 1129.803, 'duration': 4.301}, {'end': 1141.266, 'text': "i'll add it in a second and a key file name property, which is just the name of that json file.", 'start': 1134.104, 'duration': 7.162}, {'end': 1145.708, 'text': 'make sure to add dot json you just generated and downloaded and stored in your project.', 'start': 1141.266, 'duration': 4.442}, {'end': 1151.093, 'text': 'So the project ID is something you can find in the Firebase RC file, for example.', 'start': 1146.55, 'duration': 4.543}, {'end': 1153.894, 'text': "So I'll add this here also as a string.", 'start': 1151.473, 'duration': 2.421}, {'end': 1162.92, 'text': 'And this Google Cloud config has to be passed to that function we execute here when we import the Google Cloud storage package.', 'start': 1154.955, 'duration': 7.965}, {'end': 1166.582, 'text': "I'll just pass this GC config object to it to initialize that.", 'start': 1163.24, 'duration': 3.342}, {'end': 1177.049, 'text': 'and with that i now make sure that google cloud storage also works in this http trigger function and not just in the storage related cloud function.', 'start': 1167.382, 'duration': 9.667}], 'summary': 'Add project id and key file to initialize google cloud config for firebase project.', 'duration': 47.246, 'max_score': 1129.803, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1129803.jpg'}, {'end': 1351.379, 'src': 'heatmap', 'start': 1318.407, 'weight': 0.718, 'content': [{'end': 1319.248, 'text': 'Deployment finished.', 'start': 1318.407, 'duration': 0.841}, {'end': 1323.074, 'text': "And as always, let's give this a few seconds before we send the request.", 'start': 1319.429, 'duration': 3.645}, {'end': 1328.202, 'text': "And then in Postman, I'll send the same request again to Firebase.", 'start': 1324.156, 'duration': 4.046}, {'end': 1333.071, 'text': 'And I get back, it worked, which is looking good.', 'start': 1330.99, 'duration': 2.081}, {'end': 1336.232, 'text': "Now on storage, I'll reload this.", 'start': 1333.891, 'duration': 2.341}, {'end': 1339.434, 'text': 'And actually there we should see two files now.', 'start': 1337.113, 'duration': 2.321}, {'end': 1345.076, 'text': 'We see the uploaded file and the resized one, because our other Cloud Function,', 'start': 1340.094, 'duration': 4.982}, {'end': 1351.379, 'text': "which triggers upon file changes and of course this is a file change it's uploaded, so this triggers the Cloud Function.", 'start': 1345.076, 'duration': 6.303}], 'summary': 'Successful deployment, triggered cloud function, resulting in two new files in storage.', 'duration': 32.972, 'max_score': 1318.407, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1318407.jpg'}, {'end': 1372.267, 'src': 'embed', 'start': 1345.076, 'weight': 4, 'content': [{'end': 1351.379, 'text': "which triggers upon file changes and of course this is a file change it's uploaded, so this triggers the Cloud Function.", 'start': 1345.076, 'duration': 6.303}, {'end': 1353.98, 'text': 'the other Cloud Function also runs.', 'start': 1352.279, 'duration': 1.701}, {'end': 1356, 'text': 'So the resizing Cloud Function also runs.', 'start': 1354, 'duration': 2}, {'end': 1359.682, 'text': 'And here I can confirm by the date and time, this is today.', 'start': 1356.281, 'duration': 3.401}, {'end': 1362.063, 'text': 'So this works as it should.', 'start': 1360.162, 'duration': 1.901}, {'end': 1366.805, 'text': 'And with that, with some errors, we made it to the end of that.', 'start': 1362.763, 'duration': 4.042}, {'end': 1372.267, 'text': 'We have our upload file HTTP endpoint, which is triggered by an incoming request.', 'start': 1366.905, 'duration': 5.362}], 'summary': 'Cloud functions triggered by file changes and http requests, with some errors encountered.', 'duration': 27.191, 'max_score': 1345.076, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1345076.jpg'}, {'end': 1439.638, 'src': 'embed', 'start': 1418.062, 'weight': 3, 'content': [{'end': 1428.71, 'text': 'seeing some things to avoid You learned how to set up HTTP endpoints through Firebase Cloud Functions and which extra flexibility this gives you.', 'start': 1418.062, 'duration': 10.648}, {'end': 1433.153, 'text': 'Now you can build your own RESTful API on top of Firebase.', 'start': 1429.27, 'duration': 3.883}, {'end': 1434.855, 'text': 'You can use all the other features.', 'start': 1433.353, 'duration': 1.502}, {'end': 1439.638, 'text': 'You can integrate this API with the other features like we do for storage.', 'start': 1435.275, 'duration': 4.363}], 'summary': 'Learned to set up http endpoints via firebase cloud functions, enabling building restful api on top of firebase with integration of other features.', 'duration': 21.576, 'max_score': 1418.062, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1418062.jpg'}], 'start': 1052.391, 'title': 'Setting up google cloud storage and firebase cloud functions', 'summary': 'Walks through initializing google cloud storage in firebase by downloading and storing a private key and passing google cloud config to functions, and details the process of setting up http endpoints through firebase cloud functions for file uploads, including deployment and integration insights.', 'chapters': [{'end': 1228.817, 'start': 1052.391, 'title': 'Initializing google cloud storage in firebase', 'summary': 'Discusses the manual initialization of google cloud storage in firebase, requiring the download and storage of a private key from the firebase admin sdk, and the need to pass the google cloud config to functions for initialization.', 'duration': 176.426, 'highlights': ["The need to initialize Google Cloud Storage manually with the Firebase project's credentials is emphasized, requiring the download of a private key from the Firebase admin SDK. It's highlighted that the manual initialization of Google Cloud Storage with the credentials of the Firebase project is necessary, involving the download of a private key from the Firebase admin SDK.", 'The process of downloading and storing the private key from the Firebase admin SDK is explained, emphasizing the importance of adding the file to the project folder for use in Firebase Cloud Functions. The process of downloading and storing the private key from the Firebase admin SDK is explained, stressing the importance of adding the file to the project folder for use in Firebase Cloud Functions.', 'The creation of a new constant named gcconfig, specifying the project ID and key file name property for initializing Google Cloud Storage, is described. The creation of a new constant named gcconfig, specifying the project ID and key file name property for initializing Google Cloud Storage, is described.']}, {'end': 1445.483, 'start': 1228.817, 'title': 'Firebase cloud functions for file uploads', 'summary': 'Details the process of setting up http endpoints through firebase cloud functions for file uploads, demonstrating a successful deployment and providing insights on integrating the api with other features.', 'duration': 216.666, 'highlights': ['The chapter details the process of setting up HTTP endpoints through Firebase Cloud Functions for file uploads The transcript covers the setup of HTTP endpoints through Firebase Cloud Functions for file uploads, outlining the process and demonstrating the functionality.', 'demonstrating a successful deployment The transcript highlights a successful deployment of the Firebase Cloud Function for file uploads, demonstrating the practical implementation of the process.', 'providing insights on integrating the API with other features Insights are provided on integrating the API with other features, showcasing the additional functionality and flexibility available through Firebase Cloud Functions.']}], 'duration': 393.092, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/qZ1EFnFOGvE/pics/qZ1EFnFOGvE1052391.jpg', 'highlights': ["The need to initialize Google Cloud Storage manually with the Firebase project's credentials is emphasized, requiring the download of a private key from the Firebase admin SDK.", 'The process of downloading and storing the private key from the Firebase admin SDK is explained, emphasizing the importance of adding the file to the project folder for use in Firebase Cloud Functions.', 'The creation of a new constant named gcconfig, specifying the project ID and key file name property for initializing Google Cloud Storage, is described.', 'The chapter details the process of setting up HTTP endpoints through Firebase Cloud Functions for file uploads.', 'Demonstrating a successful deployment of the Firebase Cloud Function for file uploads, demonstrating the practical implementation of the process.', 'Providing insights on integrating the API with other features, showcasing the additional functionality and flexibility available through Firebase Cloud Functions.']}], 'highlights': ['The chapter demonstrates creating an HTTP Cloud Function in Firebase to listen to HTTP events and create an API, showcasing the process of exporting a new function, using the functions object from the firebase functions package, and defining on request function for executing HTTP requests.', "The video explains the process of deploying the created HTTP Cloud Function using Firebase, emphasizing the use of 'firebase deploy' command to put the function back into Firebase and create a function with the defined upload file function.", 'The speaker highlights the importance of sending a response from the HTTP Cloud Function, emphasizing the usage of status code 200 and sending JSON or HTML data as a response to the HTTP request.', 'Firebase Cloud Functions use Node Express behind the scenes, providing familiarity and ease of use.', 'Demonstrates the ability to handle specific HTTP verbs for endpoints, ensuring controlled access and functionality.', 'Utilizes Postman for testing the HTTP requests, ensuring successful deployment and endpoint stability.', "Enabling cross-origin resource sharing by installing and using the 'cors' package.", "Explains the process of setting up the 'cors' package to allow cross-origin access conveniently.", 'Using the Busboy object to parse incoming form data and listen to file events for successful file parsing.', 'Storing the detected files in Firebase Storage for future use.', 'The process involves using Busboy to access the temporary cloud storage and create a path to the file, then setting up an object to hold the file data, and finally using Google Cloud Storage to upload the file.', "The chapter emphasizes the use of Busboy's 'on file' and 'on finish' functions to handle file parsing and trigger the upload process, as well as the importance of setting MIME types for the uploaded file.", 'The author describes the process of handling upload responses, including error handling and successful file uploading, while also mentioning triggering the resize function upon successful upload.', "The need to initialize Google Cloud Storage manually with the Firebase project's credentials is emphasized, requiring the download of a private key from the Firebase admin SDK.", 'The process of downloading and storing the private key from the Firebase admin SDK is explained, emphasizing the importance of adding the file to the project folder for use in Firebase Cloud Functions.', 'The creation of a new constant named gcconfig, specifying the project ID and key file name property for initializing Google Cloud Storage, is described.', 'The chapter details the process of setting up HTTP endpoints through Firebase Cloud Functions for file uploads.', 'Demonstrating a successful deployment of the Firebase Cloud Function for file uploads, demonstrating the practical implementation of the process.', 'Providing insights on integrating the API with other features, showcasing the additional functionality and flexibility available through Firebase Cloud Functions.']}