Missing features in the "Retool Storage" Resource Query Block

I was looking at using more folders to store my files in Retool Storage but the options provided in workflows makes this difficult.

Issues

  • I can get a list of file metadata, and define a page....


    But the response does not include current page or available pages, so if I wanted to loop everything..... do we increment pages until the length of the response is less than the page size?

  • There is an option to to Get contents of file but what about get contents of folder?

    • This goes back to the first issue. Am I supposed to collect up all the files and then filter by folder manually?

Request

Add more features to the Retool Storage resource actions such as:

  • Option to Get files in folder
  • Option to Get paginated file metadata and return more information about the total, or current page, etc...

that's how i've done it, sorta. the query does actually contain (i want to say it returns a pageNumber, but that's not accurate) the page number:

the trick is that sometimes its an Int and sometimes its an empty string.
either way though, here's a little trick so you don't have to pass a variable for the page number (save some bytes lol)


this is what line 13 is for. since we already have all the files, might as well stuff em in a variable so we don't have to do all that processing again. then you can set the data source of a list view or whatever to

{{ allRetoolFiles.value.filter((file) => file.folderName.toLowerCase() === "My Folder".toLowerCase()) }}

alternatively, you could have a 2d array or object of array or just a seperate variable for each folder and you could JS to put the file in the right "folder" variable and use each of those as the data source of a list view.... the downside is speed, efficency and increased risk of logic error or edge cases, so idk it probly depends on your use case but I'd suggest keeping it all in one place so you know for sure you don't have duplicate data stored and you don't have to remember to update anything if you add or remove folders :person_shrugging:

side note:
that JS can actually be condensed:

let page = await getAllRetoolFiles.trigger();
let fileList = page

while(page.length === page.pageSize){
    page = await getAllRetoolFiles.trigger()
    fileList.concat(page)
}

await allRetoolFiles.setValue(fileList);
// We don't need to return anything since nothing depends on the return value, in fact it will save some memory if we don't since we're already storing it in a variable

or just because I VERY rarely get to use a do/while loop

let fileList = [];
let page;

do {
    page = await getAllRetoolFiles.trigger();
    fileList = fileList.concat(page);
} while (page.length === page.pageSize);

await allRetoolFiles.setValue(fileList);
1 Like

Thank you :slight_smile:

Sent me in the right direction, and now I have a nice re-usable workflow

And this is the function in the loop.

2 Likes