When it comes to the cloud, there is more than one way to serve a file. In, this article, we will walk through all the different ways to serve a file from Google Cloud Storage. It is kind of like having a yard sale, but all the stuff stays in your yard or you decide where it goes.
You probably already know Google Cloud Storage is a fantastic product to serve assets to the clients and using your application. But depending upon your application, you might need different methods of getting that data out of the GCS bucket. So, let’s take a look at the available options in detail.
A common use case is when you are hosting your files in GCS and serving them publicly to your website or application.
In this situation you will need a URL, so you can fetch things via an HTTP request. Now, while the files in GCS are by default hidden from public view, you can change the access settings to give them a unique public URL for just such a purpose. This lets you use GCS to serve static websites or serve your content to an application directly.
Now, for items that are not exposed through a public endpoint, you have a couple of more options.
1. Using Client Libraries:
First, you need to download the assets directly into your respective application, and if they don’t have publicly accessible URLs, you can use the client libraries.
2. Using GSUTIL tool
Secondly, you have a GSUTIL application. It is a python application that lets you access cloud storage from the command line. For our purposes the cp command allows you to upload files from your local machine to the cloud storage. For example, running this command will download from a GCS bucket to a local path on your device. And like any awesome tool, gsutil comes with a plethora of options to use to configure to your specific use cases. For instance, the -m command allows for copy options to occur in parallel.
gsutil cp gs:// [Bucket Name]/[Object Name][Object Destination] -m
3. Using REST APIs
You can also go to the REST APIs using other programs, like cURL, to fetch your files directly and allow the user to log in with OAuth. This one of the frequently used solutions during the development period as it automates all the processes like authorization and operation simultaneously.
4. Using the Google Cloud Console:
This is the simplest option available. To do so, Right-click on the object and select save as or click on the # dots at the object list and click on download.
This is wonderful when you are trying to grab individual files while you are debugging or manually checking through things.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.