Google Cloud Storage Upload with Node.js | Step-by-Step Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello everybody welcome to another episode of coding with a today we are going to be uploading files into our Google Cloud Storage as you can see here we have a test uploaded. dxt so we're going to automate this uploading to Google stores so how do we do this so let's get started so for this project we're going to use a Google Cloud stor a library from node so let's do first mpm in it why let's rename this to our normal Alan go that let's do CS yeah so let's do H mpm install a Google Cloud SL storage meanwhile let's do index.js and of course we're going to install the the because we require lots of these data um perfect so let's do first the require D okay let's require storage which is from Google storage okay and then let's create our function that will upload a file upload file which we're going to send in here the bucket so so where's where where is the place that we're going to save the file we're going to send the file URL actually the file um and let's send also the file output name okay and let's do a function to call this uh upload file and okay so for the bucket in our case right now what we're going to do is we're going to get that from the do okay so we're actually going to go and write the do end file and let's do um project ID let's do vet name let's do uh yeah let's do a key file name so this is going to be the Shon uh address like where do we have that Chason file and so yeah so basically you're going to do like process do and that we said bucket name the file we're going to create a new file here let's do test.txt we're going to send hello coding with other funs H so let's call it test.txt and the out file will be like a coding with a. dxt okay perfect so let's do a try catch as always really really important to always catch the Earth let's do error error perfect um so we need to First initialize the storage okay so const storage is going to be a new storage where we're going to send what we're going to set the process. do project ID and uh process yeah uh yep and the second one will be the key file name which is going to be the key file name so it's proc do key file name uh it doesn't like it uh what does like it okay I think it's the SL here let's do something nicer let's do cost project ID equals to that and send the project ID here and save here cost a key file name equals to that that key file name okay perfect so now we have storage so what we're going to do is we're going to initialize the vet connection so it's going to be the backet is going to be a storage. bucket I going to send process. end dot bucket name and actually no we have the bucket here sorry bucket um and then we're going to do an await bucket. upload and in here we're going to send the PA string so it's going to be a file and this actually requires an object where we're going to send the destination yeah file output name and I think we have a duplication name here so let's do backet name or let's s the backet name here okay cool yeah nothing is in weird colors now awesome so once we have that let's do console.log H actually do a return here uh what can we return we can return this upload so let's do c rate equals to that return that go return equals to that and let's go Sol log here and this is an a wait okay cool so now let's get all these data okay so let's go to our console go and here we are so um let's go to First API and services okay the first thing that you need to go is go to libraries search here for storage and the first one this cloud storage well I already enabled it but you'll have to click the blue button called enable Okay once you do that you can go to API and services credentials you can create a new credential which will be a service account okay we can do coding with our storage okay create and continue h cloud storage me no CL storage CL storage start continue you can feel less specific on the on the Scopes okay so basically now that you have here for examp goinging without storage we edit and we go to Keys we create the key shason create perfect and we have this coding with other okay so I'm going to move that there so give me a second so I just mov it here C with AO now let's grab all this data so for the project ID um you have to go here normally it's in your url but sometimes it gets a hidden using the name of the app okay so a trick of you is like you'll always see something like this you know one of the service accounts or your client ID when you create them you have the same number here that's your project ID which has gra there let's go to now to backets to cloud storage let's create a new bucket let's do coding with Auto continue multi region which we want that let's set default let's get uniform non create enforce Public Access prevention to This n we don't need that right now because we want to be aess able to access those files in public confirm perfect coding with that's our bucket okay and the key file name it's the coding with a. Json okay so it's this file awesome so let's clear this out in here you see there's nothing so let's do node index not Lo the credentials because the getting started from okay uh I think that you cannot access the file okay let me see okay so let's de this um so let's do oh okay so I think we need to change the place where we do all this so we need to First require this torage first in initialize the storage okay now once you have the storage then in theing function it can go and call that because we need to initialize this before we call this s function I think that's the issue let's run this I couldn't get the credentials okay I think it's not getting to the and let me doing a sh PCH here and let's do the project maybe here okay what some missing here could not leave theault credentials okay I think I know so yeah okay so this is the problem uh when we go to storage we see that the names are perfect IDE which is fine but the key F name it's key with f never case Okay so let's go back here let's do process do and do a key file name name I think it's that key file name yep and for pro let's do process. do project okay cool uh yeah and let's replace that name here there perfect yay perfect so when we have we go here we'll see our coding with. dxt which is for right now 1442 1442 we can open that we can oh we can access that yeah hello cing with tant awesome perfect okay so yeah that's how you upload a file into Google Cloud stour thank you very much much for watching this is coding with Ado if you like this content download subscribe like leave your comments H I'm taking requests I'm doing a speech to text next I think it's one of our subscribers just recommended so yeah see you on the next episode bye-bye
Info
Channel: Coding with Ado
Views: 4,908
Rating: undefined out of 5
Keywords: google cloud storage, gcs, aws s3, s3, nodejs, tutorial
Id: kojaR6LBdzI
Channel Id: undefined
Length: 14min 23sec (863 seconds)
Published: Thu Oct 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.