简体   繁体   中英

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 . 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. 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 .

You need to provide the Bucket ID and should have the access to the bucket to read the objects. You can try the API before implementing it in your code.

I hope that helps.

You do not need billing enabled to download objects from a GCS bucket. Operations on GCS buckets are billed to the project that owns the bucket. You only need to enable billing in order to create a new bucket.

Downloading a single file using the Gcloud gem looks like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM