Search all files in bucket
# help
a
Search all files in bucket
I need to search all files in a particular storage bucket for files or folders with a name containing a search term. My current implementation only searches a particular folder, how can I make it search everything?
`const { data, error } = await supabase .storage .from('core-content') .list('/', { limit: 100, offset: 0, sortBy: { column: 'name', order: 'asc' }, search:
%${searchPattern}%
});`
g
The docs say the folder path is optional. Not tested, but try putting null, {.....
a
folder path type is string | undefined so I tried undefined, still seems to only return results from the top level in the bucket
g
Have you actually seen any documentation on search (which is very new) other than the one example in the storage reference? I just looked at the source and it does seem to think about "levels" of folders. It then calls an rpc function "search" which I've not tracked down. You might be better off just querying the storage.object table with a where on bucket id (name) and ilike or like on your name...
FYI here is the search function, which technically you could call, but I did not dig into exactly how levels is used, other than it is sent bases on number of "/" in the path. https://github.com/supabase/storage-api/blob/master/migrations/tenant/0009-search-files-search-function.sql
a
Thank you very much for your assistance so far! I have only seen that one example, wasn't sure if there was missing functionality or it was just taking a while for the docs to get fleshed out a little better. I will try querying the tables directly and see how far I get with that. Thanks again!
Doesn't look like I can query the storage tables directly because the JS library automatically appends the public schema name to queries so I have created a view in the public schema that exposes the storage.objects table and includes the appropriate access restrictions in it's definition (combination of inner join and where clause in my situation). Looks like this will work for my use case, let me know if this approach seems ok. Thanks 🙂