HTTPSocket File Upload Hang

Having issues with uploading a file to octoprint print server. The following curl script works fine.

 curl -k -H "X-Api-Key: 1234567890" -F "select=true" -F "print=false" -F "file=@Bench.gcode" "http://octopi/api/files/local" 

The following code is what I have configured in a button. When I run this code it times out and I have to restart the
server because it becomes non responsive and the application looses the ability to poll the server. This should not timeout
the curl script runs in less than 2 seconds.

[code]Using Xojo.Core
Using Xojo.Data
Dim Octo As New OctoSocket
Dim data As MemoryBlock
data = TextEncoding.UTF8.ConvertTextToData(dataF)

Octo.SetRequestContent(data, “multipart/form-data; boundary=----WebKitFormBoundaryDeC2E3iWbTv1PwMC”)
Octo.RequestHeader(“X-Api-Key”) = apikey
Octo.Send(“POST”, “http://octopi/api/files/local”)[/code]

OctoSocket is the Class where I have defined: Xojo.Net.HTTPSocket
dataF is a constant that contains the following data

Content-Disposition: form-data; name="file"; filename="@Bench.gcode"
Content-Type: application/octet-stream

M109 T0 S220.000000
Content-Disposition: form-data; name="select"

Content-Disposition: form-data; name="print"


The file content is embedded for simplicity and is the same content the curl script uploads. Once I have it working
I can then read the complete file in. I can successfully post to the server with json data without any issues. So I must be doing
something wrong in how I am sending the upload post. Can anybody determine what I am doing wrong?


Try leaving out the @ symbol from the file name. I’m pretty sure that’s part of the command line syntax rather than part of the file name.

Also, the boundary string should have two more hyphens prepended when being used in the form.

i.e. if you set boundary=--Foo in the header, then the form elements use ----Foo (and the last boundary is ----Foo--

Here’s some code that generates the form automatically from a Dictionary.


Tried both suggestions no change is the result. Although I had boundary=----Foo and in the data I had ------Foo I changed it to 2 and 4 respectively per your post. Unfortunately nothing changed, I also removed the @ and that did not help either. I am new to HTTPsocket, but I can send json data all day long. Could there be some other switches or settings that are required to upload a file?

Here is some additional information The app eventually gets a timeout error and the PageRecieved event never fires. It seems like the request is never officially closed so everything is left hanging.

The only thing I can think of is the -k argument, which disables SSL certificate validation. The equivalent in Xojo.Net.HTTPSocket is to set the ValidateCertificates property to False.

You can translate those curl command line easily to calls for MBS CURL Plugin. If needed I can help.

I might have to go that route but not ready to give in yet.

No joy on the ValidCertificates=False.