I had used that demo to generate some test code.
while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs, var_name, sizeof(var_name), file_name, sizeof(file_name), &file_data, &data_length)) > 0) {
mg_printf_data(conn, "var: %s, file_name: %s, size: %d bytes<br>", var_name, file_name, data_length);
}
While data_length is coming out to what appears to be the correct (or very close to correct) length, the file_data contains literally everything the browser sent: Referer data, encoding information, the multipart borders, and sometimes more than one copy of the actual file data, like such from a short text file:
Hello World!
------WebKitFormBoundaryv2aFgLWYR3PyxBwq--
.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Content-Type: multipart/form-data; boundary=------WebKitFormBoundaryv2aFgLWYR3PyxBwq
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0,8
------WebKitFormBoundaryv2aFgLWYR3PyxBwq
Content-Disposition: form-data; name="file"; filename="uploadtest.txt"
Content-Type: text/plain
Hello World!
------WebKitFormBoundaryv2aFgLWYR3PyxBwq--
Any ideas on what I might be doing wrong here?