Echo
Echo

Reputation: 405

Google storage api list storage bucket with "/" in the name

I am trying to list all objects in a bucket(Google storage) in the google storage api. The bucket is nested like a folder, such as "my-bucket/sub-folder". I got the following error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found

If I use a bucket name without "/" it works fine. How can I list a bucket like a folder structure?

Upvotes: 2

Views: 1738

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38399

Google Cloud Storage buckets do not have slashes in their name. In the example above, the bucket is named "my-bucket" and the object is named something like "sub-folder/object.txt" or just "object.txt".

It's useful to remember that GCS does not have any real notion of folders. There are only buckets and objects in buckets. If you have a subdirectory named "dir" in bucket named "mybucket", and that subdirectory has 5 objects in it, what you really have is 5 objects named "dir/obj1", "dir/obj2", etc, all still within bucket "mybucket."

A number of tools (like gsutil and the GCS web-based storage browser) make it appear that there are folders, through use of markers and prefixes in the API -- even though as noted, there really are just objects that have slashes in the name.

Upvotes: 7

Related Questions