I created a simple event handler
//Event handler for CGI calls from client Javascript
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
const char *data;
int data_len;
char var_name[100], file_name[100];
if (ev == MG_REQUEST)
{
if (strcmp(conn->uri, "/handle_post_request") == 0)
{
if (mg_parse_multipart(conn->content, conn->content_len,
var_name, sizeof(var_name),
file_name, sizeof(file_name),
&data, &data_len) > 0)
{
mg_printf_data(conn, "%s", "Uploaded file:<pre>");
mg_send_data(conn, data, data_len);
mg_printf_data(conn, "%s", "/pre>");
}
return MG_TRUE;
}
else
{
return MG_FALSE;
}
}
else if (ev == MG_AUTH)
{
return MG_TRUE;
}
return MG_FALSE;
}
I then created a html page:
* <html><body> Upload example. <form method='POST'
action="/handle_post_request" enctype="multipart/form-data"> <input
type="file" name="file" /> <br/> <input type="submit" value="Upload"
/> </form></body></html> When I upload a file, the content_len is zero
and mg_parse_multipart () returns 0 because of it. What am I doing
wrong? *
*char* var_name[100], file_name[100];
*if* (ev == *MG_REQUEST*)
{
*if* (*strcmp*(conn->uri, "/handle_post_request") == 0)
{
*if* (mg_parse_multipart(conn->content, conn->content_len,
var_name,
*sizeof*(var_name),
file_name,
*sizeof*(file_name),
&data, &data_len) > 0)
{
mg_printf_data(conn,
"%s", "Uploaded file:<pre>");
mg_send_data(conn, data, data_len);
mg_printf_data(conn,
"%s", "/*pre*>");
}
*return* *MG_TRUE*;
}
*else*
{
*return* *MG_FALSE*;
}
}
*else* *if* (ev == *MG_AUTH*)
{
*return* *MG_TRUE*;
}
*return* *MG_FALSE*;
}
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.