oscar serrano
oscar serrano

Reputation: 241

List the files and folder within a folder in google cloud storage using JSON API

I know Google Cloud Storage doesn't manage folders, but let say I have this file:

mybucket/documentation/user

and I want all files that are within documentation/user but not those under documentation/user/version1/ or documentation/user/version2/

I want to see that under documentation/user there are 2 files (version1/ and version2/) but I don't want to get the files within recursive folders.

Is it possible using the JSON API? I know the concept of delitimer. But it only works on the root of the bucket. If I use the / as delimiter on the root I get al folders and files within the root of the bucket, but when I use the prefix documentation/user with delimiter "/" I get an empty list :-(

Upvotes: 4

Views: 2506

Answers (2)

Krishna
Krishna

Reputation: 5644

Here's the generic rule -

https://www.googleapis.com/storage/v1/b/{bucket}/o?prefix={URL Encoded Name of the object}

In the above case it would be -

https://www.googleapis.com/storage/v1/b/{bucket}/o?prefix=document%2Fuser/

The delimiter '/' is used to contain the search result within the prefix. If no delimiter is used then all the children node are also searched and the result is returned.

Upvotes: 1

Patrice
Patrice

Reputation: 4692

As pointed out by jterrace, using

delimiter = /

and

prefix = documentation/user/

should get you what you want. Note : the folders will not return in the "items" portion of your JSON response, but in the "prefixes" field. (that part was taken from the OP)

Upvotes: 3

Related Questions