How to get S3 signed-urls for all rows of a table (result of another query)

I have table-1 with say 50 rows in which one column has some short urls for files on AWS S3.
I want to create another query where I use the S3 resource with the "Generate a signed url" action-type to get the 50 signed urls corresponding to each row of the table-1.
Can someone please help me figure out can this be done?

I know how to do this for the selected row of the table-1. But I want to get it for all the 50 rows and save the signed-urls as table or export as json.

Hi Vicki, yes there's a way you can turn a query on a single row into a query for all rows. First, configure your single-row query using a variable wrapped in {{}}. Here I use the variable key - think of this as a argument in a function, you can name it whatever you like:


Then, create another JavaScript query. In this query, you can trigger the single-row query (in this example, I named it query2) for an array of data like so:

return Promise.all(query1.data.Contents.map(c => {
return new Promise(resolve => query2.trigger({
additionalScope: {key: c.Key},
onSuccess: (data) => {
resolve(data)
}
}))
}))
Notice the parameter additionalScope: {key: c.Key} - key here should be the same as the previous variable name we specify in query2. The onSuccess trigger will provide the data returned from running the single-row query.
Lastly, by returning a Promise, you can make sure that retool will treat the query as running until the Promise is resolved.

Feel free to reach out again if you have any questions!



I've prepared a version here to get signedURL as the { Key: X } was not working in the above example.

Step 1 - Get a list of images from a GCS bucket in a table.

Step 2 - make a JS query (myquery) and paste this code:

const promises = tablename.data.map(row => {
    return getImageSingle.data.trigger({
        additionalScope: {
            name: row.name  // you can make .name whatever column name you want to iterate over
        }
    });
});

return Promise.all(promises);

Step 3 - create a getImagesSingle as such

Step 4 - go back and run your query from above and you should get a result with all of the images which can then be referred to as: {{ myquery.data['0'].signedUrl }}

2 Likes

As a follow up - rather than creating a new table result, how would I just make a new column in tablename that holds the signedUrl? I want to be able to select a row and just instantly have hte signedUrl without needing another lookup (i.e. tablename.selectedRow.signedUrl along with whatever else is in the table to begin with)

As an additional bonus.... what if I have two columns in tablename that I wanted signedUrls for.
It would be great if I could access those as say (tablename.selectedRow.signedUrlFirst tablename.selectedRow.signedURLSecond) @retool_team @victoria @alina.retool would be a fantastic help if possible - thank you!

Hey @griffxbio! Are these columns custom columns? Getting all of the data from the table is a little tricky with custom columns since they are frontend only.

It might be easier to use a transformer to create those columns in the table data, rather than to use custom columns!

Otherwise, you could reference the SQL data with tableName.data and the custom column data with tableName.columnMappers, depending on the setup of the custom column: