mg_parse_multipart is slightly vague - how to read an upload to a buffer?

225 views
Skip to first unread message

John Peasley

unread,
Sep 23, 2014, 10:49:08 PM9/23/14
to mongoos...@googlegroups.com
I've got a situation where I need to be able to use mg_parse_multipart to accept an upload. I've got that part of it working, but the buffer that I'm reading to seems to be including the boundary markers, HTML headers, referer data, and so forth.

The documentation/examples for this aren't entirely clear on what I should be doing. How can I get just the data for the uploads? It won't matter if they're concatenated in this case, since it's all going to be straight text that's going to get parsed.

Sergey Lyubka

unread,
Sep 24, 2014, 2:05:50 AM9/24/14
to mongoose-users
Hi John,

On Wed, Sep 24, 2014 at 3:49 AM, John Peasley <fire...@gmail.com> wrote:
I've got a situation where I need to be able to use mg_parse_multipart to accept an upload. I've got that part of it working, but the buffer that I'm reading to seems to be including the boundary markers, HTML headers, referer data, and so forth.

The documentation/examples for this aren't entirely clear on what I should be doing. How can I get just the data for the uploads? It won't matter if they're concatenated in this case, since it's all going to be straight text that's going to get parsed.

--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.

John Peasley

unread,
Sep 24, 2014, 4:36:27 AM9/24/14
to mongoos...@googlegroups.com
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? 
Reply all
Reply to author
Forward
0 new messages