URLConnection SetRequestContent Help

I can successfully send out cURL from the Windows command line, but when I try to create the equivalent SetRequestContent lines in Xojo, I get a “Could not parse multipart form”.
So, this works from the command line:
-F model=“STT1”
-F file=“@C:/Audio/query.wav”
How do I code this in Xojo using SetRequestContent?
Every attempt gives me the “could not parse” message.
I know I’m getting my headers correct, including the auth key.
For example, this doesn’t work:
OpenAIconnection.SetRequestContent(“model=”“STT1"”“, “multipart/form-data”)
OpenAIconnection.SetRequestContent(“file=””@C:/Audio/query.wav"“”, “audio/x-wav”)
There are no compile errors, just the “could not parse” message when ContentReceived fires.

-F specifies a form element in a multipart/form-data encoded HTTP form. The URLConnection can’t generate this kind of form for you, you’ll need to generate it yourself and then give it to the URLConnection to send.

To generate the form yourself you can use this project:


Dim uc As URLConnection = New URLConnection()
Dim multipartContent As New MultipartFormDataContent()
Dim f As FolderItem = GetFolderItem("C:/Audio/query.wav")
multipartContent.Add("file", f))
Dim result as String = uc.SendSync("POST", "http://www.example.com/submit.php")

See also this project for using OpenAI:

1 Like

Andrew, thanks for the advice and code and link. I’m looking forward to trying it. I’ll be back with an update.

Andrew, I just wanted you to know that it’s working as of yesterday based on your advice. Thanks! I’ll try to pay it forward, the time that you saved me.

1 Like