2
votes

In google cloud storage, i have bucket called cats inside a root bucket called images. Im using the google-api-ruby-client gem to upload files. Im able to upload a file to the root bucket 'images' but uploading to 'images/cats' does not work. I am aware that the buckets in google cloud storage do not have a notion of slash, so I'm unable to figure out how to specify the name of the nested bucket.

result = client.execute(
  api_method: api.objects.insert,
  media: media,
  parameters: {
    uploadType: 'resumable',
    bucket: 'images/cats',  #This does not work !. Just images works.
    name: 'kitty.jpeg',
  },
  body_object: {contentType: 'image/jpeg'}
)

This is giving the error NoMethodError: undefined method query_values for nil:NilClass. The code works if i just use 'images' for the value of the bucket.

How can i make the upload work for nested buckets as well ?

Thanks

1

1 Answers

5
votes

Google Cloud Storage doesn't have true directories - it has a flat namespace. You can partially simulate directories by using "/" characters in your object names, and using prefix and delimiter queries when listing buckets.

The problem you're seeing is caused by the fact that bucket names can't contain "/". Try instead using the bucket "images" and object names that start with "cats/".