How to export data as POST Form Data attachment?

I'm trying to export data but instead of prompting the user to download a file, I would like to send the exported data (from a table in my use case) to an API using a File parameter in a POST as Form Data parameter.

Is there a way to accomplish this?

Thanks in advance

@rferland

Hey there :wave: Export data does specifically download the file, but you should be able to build a retool app that organizes the data and sends it via an API request!

I am attempting the same, but am fairly new to Retool so struggling a bit. Would you be able to provide some more guidance on "build a retool app that organizes the data and sends it via an API request"? Just plainly putting my myTable.data in the body is very naive of course and clearly doesn't do the job... Any help would be much appreciated!

@Lewiszz Can you share what data you have and what data you want to send? You'll likely need to use a JS query to manipulate the data, but the exact steps etc depend heavily on what you are trying to do.

Hi @joeBumbaca, thanks for responding. I managed to get it to work using the following preloaded JS function:

window.toFile = function (tableName, tableData) {
  const txtFile = btoa(JSON.stringify(tableData))

  const txtFileInfo = {
    name: tableName + ".txt",
    size: txtFile.length,
    type: "application/txt",
    data: txtFile
  }
  return txtFileInfo;
}

I call this when users click the export button, and pass the result along to my API query.

1 Like