# HTTPSocket File Upload Hang

**URL:** <https://forum.xojo.com/t/httpsocket-file-upload-hang/46197>\
**Category:** General\
**Created:** [November 10, 2018, 3:10pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197 "2018-11-10T15:10:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Omiccioli](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@Michael\_Omiccioli](https://forum.xojo.com/u/Michael_Omiccioli)\
**Post date:** [November 10, 2018, 3:10pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/1 "2018-11-10T15:10:54Z")

</div>

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

```auto
 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](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

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

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

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

false
------WebKitFormBoundaryDeC2E3iWbTv1PwMC--
```

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?

Thanks

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [November 10, 2018, 5:49pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/2 "2018-11-10T17:49:06Z")

</div>

> [@413643:@Michael Omiccioli](#):
>
> Content-Disposition: form-data; name=“file”; filename=“@Bench.gcode”

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.

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [November 10, 2018, 6:04pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/3 "2018-11-10T18:04:35Z")

</div>

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](http://www.boredomsoft.org/file-uploads-form-encodings-and-xojo.bs) some code that generates the form automatically from a Dictionary.

---

<div class="post-metadata">

**Author:** ![Michael\_Omiccioli](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@Michael\_Omiccioli](https://forum.xojo.com/u/Michael_Omiccioli)\
**Post date:** [November 10, 2018, 8:17pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/4 "2018-11-10T20:17:59Z")

</div>

Andrew,

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?

---

<div class="post-metadata">

**Author:** ![Michael\_Omiccioli](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@Michael\_Omiccioli](https://forum.xojo.com/u/Michael_Omiccioli)\
**Post date:** [November 10, 2018, 8:31pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/5 "2018-11-10T20:31:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [November 10, 2018, 8:37pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/6 "2018-11-10T20:37:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [November 10, 2018, 8:38pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/7 "2018-11-10T20:38:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Omiccioli](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@Michael\_Omiccioli](https://forum.xojo.com/u/Michael_Omiccioli)\
**Post date:** [November 10, 2018, 8:52pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/8 "2018-11-10T20:52:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Omiccioli](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ba8739/32.png) [@Michael\_Omiccioli](https://forum.xojo.com/u/Michael_Omiccioli)\
**Post date:** [November 10, 2018, 8:56pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/9 "2018-11-10T20:56:45Z")

</div>

No joy on the ValidCertificates=False.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:27pm UTC](https://forum.xojo.com/t/httpsocket-file-upload-hang/46197/10 "2020-10-29T19:27:21Z")

</div>


