使用API​​为Google Cloud Storage Bucket对象生成自定义网址 [英] Generate custom urls for google cloud storage bucket's object using api

查看:54
本文介绍了使用API​​为Google Cloud Storage Bucket对象生成自定义网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以为云存储桶的对象创建自定义URL,这不应该像这样: https://storage.googleapis.com/sunny-incentive-185405.appspot.com 吗?

我需要类似以下内容的域名:domain.com/video-url

我能做到吗?

解决方案

为了实现您要查找的内容,我将使用存储在存储桶中的资源创建一个网页.例如,使用HTML5 视频元素和您发布的资源之一,您可以编写像这样的东西:

  index.html:< html><身体><视频宽度="320"高度="240"自动播放>< source src ="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> 

一旦允许HTTP流量到达您的实例,您就可以使用托管页面的实例的IP地址访问您的资源.因此,此时 http://your_instance_ip/index.html 现在将允许您下载视频.

然后,您将需要购买(或免费获得)域名来解析您的IP.为此,只需创建一个"A记录"以指向服务器的IP.您可以依赖提供商,也可以使用 Google DNS ,但基本上可以只是运行一些测试,结果是一样的.使用他们的教程来做到这一点,应该没有那么困难.

因此,如果您需要为存储桶中的每个视频创建自定义网址,则可以扫描正在运行的存储桶中的内容

  gsutil ls gs://yourbucketname/yourfolder 

,然后将输出重定向到脚本,以针对每个具有不同名称和URL的视频在同一路径中创建并存储同一页面.

也许不是那么简单,所以我会花更多的时间.例如,要在全新的Google Compute Engine Ubuntu实例中运行网页,您需要先安装 apache2 ,然后将html保存在/var/www/html/index.html ,然后您就可以点击实例详细信息中的标志来允许HTTP流量了.

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

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 something like: domain.com/video-url

can I achieve that?

解决方案

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>
    <video width="320" height="240" autoplay>
      <source src="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

这篇关于使用API​​为Google Cloud Storage Bucket对象生成自定义网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆