I want to upload binaries with HTTP PUT


I am a beginner with regards to phoenix.
I need a replacement for an existing build pipeline which fetches and uploads build artefacts from/to a web server with GET and PUT.

I get GET, but am about halfway with PUT…

I have a route:

put "/upload" UploadController, :put

I use curl as client:

curl -X PUT -v -H "Content-Type: application/octet-stream" --data-binary @binary_file localhost:4000/upload

I noticed that curl is careful and first only sends the length of the binary and a 100 continue,
so I answer with a 100 continue in the controller:

And in the respective controller there is:

def put(conn, params) do
    # do some length checking and whatnot
    send_resp(conn, 100, "")

curl is happy and continues with a PUT and the data.
Wireshark shows me that all is transmitted, but I think I should get an error message about a missing
callback or come again into the put method with different parameters, but nothing.

Any pointers, please?

update, this is the output of curl:

*   Trying
* Connected to localhost ( port 4000 (#0)
> PUT /upl/x HTTP/1.1
> Host: localhost:4000
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Type: application/octet-stream
> Content-Length: 3400
> Expect: 100-continue
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
< cache-control: max-age=0, private, must-revalidate
< content-length: 0
< cross-origin-window-policy: deny
< date: Wed, 25 Jan 2023 19:36:11 GMT
< server: Cowboy
< x-content-type-options: nosniff
< x-download-options: noopen
< x-frame-options: SAMEORIGIN
< x-permitted-cross-domain-policies: none
< x-request-id: Fz2kYMP9txZw4X0AAA-R
< x-xss-protection: 1; mode=block
* We are completely uploaded and fine
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

I believe you’re overthinking this - the underlying cowboy machinery already handles the flow with Expect: 100-continue:


Thank you for the link to cowboy!
Weill, in my current configuration cowboy does not send the 100-continue, I have to do it.
But I am obviously doing something wrong.

In the meantime I found Plug.Upload and Plug.Parsers, which look promising.
The documentation is a bit sparse for a newbie, so I would be grateful for a working example.
Have not found one so far…