Skip to content Skip to sidebar Skip to footer

Generate Custom Urls For Google Cloud Storage Bucket's Object Using Api

Is there any way to create a custom URL for an object of cloud storage bucket, this should not be like: https://storage.googleapis.com/sunny-incentive-185405.appspot.com ? I need

Solution 1:

In order to achieve what you are looking for I would create a webpage using that resource stored in the Bucket. For example using the HTML5 video element and one of the resources you posted, you can write something like this:

index.html:

<html><body><videowidth="320"height="240"autoplay><sourcesrc="https://storage.googleapis.com/sunny-incentive-185405.appspot.com/a-movie/1711/21/100000_Bad_Jokes_The_Movie_English_Subtitles_106.mp4"type="video/mp4"></video></body></html>

Once you allow the HTTP traffic to reach your instance, you will be able to access to your resources with the IP address of the instance hosting the page. Therefore at this point http://your_instance_ip/index.html will now allow you to download your video.

Then you will need to buy (or get for free) a domain name in order to resolve your IP. To do so just create an "A record" to point to the IP of your server. You can rely on the provider or you can use the Google DNS, but basically if you are just running some tests the result is the same. Use Their tutorial to do so, it should not be that difficult.

Therefore if you need to create a custom url for each video in your bucket you can scan the content of your bucket running

gsutil ls gs://yourbucketname/yourfolder

and redirecting the output to a script create and store in the same path the same page for each video with a different name and a different URL.

EDIT: Maybe it is not that straightforward so I will spend a couple of words more. To run the webpage for example in an brand new Google Compute Engine Ubuntu instance you need to install apache2 first and then save the html in /var/www/html/index.html and you can allow the HTTP traffic clicking on the flag from the detail of the instance.

sudo apt-get install apache2
sudo vi /var/www/html/index.html

Post a Comment for "Generate Custom Urls For Google Cloud Storage Bucket's Object Using Api"