简体   繁体   English

使用Rails从Google Cloud Storage获取共享存储桶

[英]Get shared buckets from Google Cloud Storage using Rails

I want to download some reports from Google Cloud Storage and I'm trying the Gcloud gem . 我想从Google Cloud Storage下载一些报告,并且正在尝试Gcloud gem I managed to successfully connect and now I am able to list my buckets, create one, etc. 我设法成功连接,现在可以列出我的存储桶,创建存储桶等。

But I can't find a way to programically get files from buckets, which are shared with me. 但是我找不到一种以编程方式从存储桶中获取文件的方法,这些存储桶是与我共享的。 I got and address like gs://pubsite... and I need to connect to that bucket, to download some files. 我得到的地址类似于gs://pubsite... ,我需要连接到该存储桶以下载一些文件。 How can I achieve that? 我该如何实现? Do I need to have billing enabled? 我需要启用计费功能吗?

In order to list all the object in a bucket you can use Google Cloud Storage Object list API . 为了列出存储桶中的所有对象,您可以使用Google Cloud Storage Object list API

You need to provide the Bucket ID and should have the access to the bucket to read the objects. 您需要提供存储桶ID,并且应该有权访问存储桶以读取对象。 You can try the API before implementing it in your code. 您可以先尝试使用API​​,然后再在代码中实现它。

I hope that helps. 希望对您有所帮助。

You do not need billing enabled to download objects from a GCS bucket. 您无需启用结算即可从GCS存储桶下载对象。 Operations on GCS buckets are billed to the project that owns the bucket. GCS存储桶上的操作会向拥有该存储桶的项目收费。 You only need to enable billing in order to create a new bucket. 您只需启用计费即可创建新的存储桶。

Downloading a single file using the Gcloud gem looks like this: 使用Gcloud gem下载单个文件如下所示:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "pubsite"
file = bucket.file "somefile.png"
file.download "/tmp/somefile.png"

There are some examples at http://googlecloudplatform.github.io/gcloud-ruby/docs/v0.2.0/Gcloud/Storage.html http://googlecloudplatform.github.io/gcloud-ruby/docs/v0.2.0/Gcloud/Storage.html中有一些示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google云端存储 - Rails网络应用 - 针对不同环境的不同存储桶和不同的访问密钥 - Google Cloud Storage - Rails web app - different buckets and different access keys for different environments 如何从Rails的Google Cloud Storage中从存储桶中获取所有对象 - How can I get all objects from bucket from Google Cloud Storage by Rails 没有 storage.buckets.list 访问 Google Cloud 项目的权限? - Does not have storage.buckets.list access to the Google Cloud project? 使用Paperclip和Rails,Google Cloud Storage请求速度很慢 - Google Cloud Storage requests are slow using Paperclip and Rails Rails - 将私有文件上传到 Google Cloud Storage - Rails - Upload private file to Google Cloud Storage 在Rails网站上将图像上传到Google云存储 - Uploading an image to google cloud storage on a rails site 在 Google App Engine 上从 Google Cloud Storage for Ruby on Rails 应用程序加载图像 - Loading images from Google Cloud Storage for Ruby on Rails app on Google App Engine 在Ruby on Rails应用程序中使用云存储存储图像 - Using cloud storage for images in a Ruby on Rails app 使用带有自定义域的私有谷歌云存储 - Using a private google cloud storage with a custom domain 如何使用Rails和Paperclip在Google云端存储上存储照片? - How to use Rails and Paperclip to store photos on Google Cloud Storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM