I am trying to build a web server using sockets. I have the parser for GET requests and now I want to be able to send an image to the server from a form.
After printing the request header this is what I got:
POST / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------15680533759245126501880539822
Content-Length: 14006
Origin: http://127.0.0.1:8080
Connection: keep-alive
Referer: http://127.0.0.1:8080/form.html
Upgrade-Insecure-Requests: 1
-----------------------------15680533759245126501880539822
Content-Disposition: form-data; name="textline"
4213124124123123153534123412
-----------------------------15680533759245126501880539822
Content-Disposition: form-data; name="datafile"; filename="5.jpg"
Content-Type: image/jpeg
����
This is my form:
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <form action="/"
        enctype="multipart/form-data" method="post">
        <p>
            Type some text (if you like):<br>
            <input type="text" name="textline">
        </p>
        <p>
            Please specify a file, or a set of files:<br>
            <input type="file" name="datafile">
        </p>
            <div>
            <input type="submit" value="Send">
            </div>
        </form>
    </body>
</html>
My questions are: Why do I receive only 4 bytes from the image and what should I do to be able to save the data receive in a jpg file?