Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Help with Mongoose Library Example Code - File upload

march816march816 Philippines

Good Day,

First of all, I would like to thank everyone and the team for the mongoose project.

I am currently studying and trying out the library for my embedded project.

Currently I am trying the 'file upload' example found on:
https://cesanta.com/docs/http/upload.html

I am successful in running the example .c server and html and now able to upload files.

I would just like to ask for your help on how to modify it so after uploading a file, the current web/html page does not change or goes back to the current page.
In the example it goes to a web page saying 'OK, # bytes sent, etc..'
I guess this is due to the mongoose's "mg_file_upload_handler()" function.

Right now I am using a hardcoded way by serving the same HTML file like..
mg_http_serve_file(c, h_m, "load.html", mg_mk_str("text/html"), mg_mk_str("")); ...after the mg_file_upload_handler().

`
void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
switch (ev) {
case MG_EV_HTTP_REQUEST:

       mg_serve_http(c, (struct http_message *) ev_data, s_http_server_opts);     
       hm = ev_data;
       break;

    case MG_EV_HTTP_PART_BEGIN:

    case MG_EV_HTTP_PART_DATA:

    case MG_EV_HTTP_PART_END:
        mg_file_upload_handler(c, ev, ev_data, cb);
        //memset (filename_copy, 0, sizeof (filename_copy));
       //strncpy(filename_copy, link1, filename_length);
       mg_http_serve_file(c, hm, "load.html", mg_mk_str("text/html"), mg_mk_str(""));      // <---- to override the default library mg_print
     break;
 }

}
`

How do you suggest in making it more dynamic so it reloads the page without typing the filename?
(I also have tried processing the filename at the initial MG_EV_HTTP_REQUEST)

Sorry I am a newbie at this. Thank you for your time everyone :)

Warmest Regards,
Marc

Sign In or Register to comment.