Uploading Files to OpenAI /files endpoint

Has anyone successfully uploaded a file using the Retool OpenAI resource to the POST /file endpoint?

I've tried many different formats and keep getting back:

{
  "error": {
    "message": "The browser (or proxy) sent a request that this server could not understand.",
    "type": "server_error",
    "param": null,
    "code": null
  }
}

I've been trying to populate the file field in the request with a value from a file upload component. That component seems to turn anything into Base64, so maybe OpenAI is rejecting this?

Here's what I'm seeing:

It seems like OpenAI just wants the CSV and not the base64 conversion, but is there a way to just send the actual CSV file from the filepicker?

Did you find a solution to this? Same issue here.

I had this same issue and found that the only way to make it work was to not use the included OpenAI query and instead, use a REST API query to make a POST request to the /files endpoint, setting the content type as Form Data, and including the body's purpose and file.

It seems like the OpenAI query that Retool provides has the content type as JSON where purpose and file is expected to be a string. I tried a bunch of different methods but I couldn't get the API to accept the file as any kind of string - it needs to be a file object and Form Data (in a REST API query) seems to be the only way to have purpose as a string and file as a file object.

might need the content-type header set to multipart/form-data.

Hey there @andre-ani, I'm not sure how you've got this to work. I get the whole REST API thing, and basically did the same as you did on the screenshot.

Where I'm lost is the siteDataForm thing. Is it a component? A query? I've tried a few things in that file key/value input:

  • the file dropper component and the file input component: their value is an array of objects, and the file content is only available as base64, which doesn't work
  • a Retool Storage ressource query, set to "Get contents of a file". Same as for the file dropper, the query data is simply an object with a few metadata and the base64Data key.
  • converting the base64 string to a File object and using this in the file value input, and I've got a weird error out of it (kind of expected as this is really fat-fetched).

Could you help me out please?

Nevermind. The data of the Retool Storage query ({{query.data}}) works just fine.