Retool Storage Folder Name Use Variable to Upload into a sub-directory

I am trying to upload files to Retool Storage and store the files in a subdirectory and then create a new folder based on the value they select from a select component. I can create the folder from the select component but cannot figure out how to get it to go into the right subdirectory one level up. For example, I have the following sub-directory in retool storage:

RRL

and when a user selects the value from the select component I want the file to go into RRL/{{ select1.value}}. I can only get it to create the new folder off of the root and not in the RRL sub-directory.

Is this possible to do?

Retool Storage only supports a single level of folders at the moment (so no subdirectories). Using a prefix could be a sufficient workaround?

In that case, how can I save a filename, with the prefix of the filename being the select component value. I would also like to save this newly name file in a subdirectory. For example:

filename: labels.pdf
select component value: #1070
subdirectory: RRL

In the Retool Storage RRL Directory I would like a file name #1070-labels.2025-03-25.pdf

To modify the filename, it's necessary to click the "fx" button to the right of File source and manually refer to a file widget.

As an example, in the attached screenshot, I've set:

  • File content: {{ fileInput1.value[0].base64Data }}
  • File name {{ select1.value }}--{{fileInput1.value[0].name }}
  • Folder name prefix-{{ moment().format('YYYY-MM') }}

If you need to insert date before extension in the filename itself, then you might need to write something like File name

{{  
  function(){ 
  const fileName = fileInput1.value[0].name;
  const lastDot = fileName.lastIndexOf('.')
  return `${fileName.substring(0, lastDot)}.${moment().format('YYYY-MM-DD') }${fileName.substring(lastDot)} `
}() 
}}

Does that help?

Yes, it does. Thank you!

1 Like