Hi David,
It took me a while to get back to this but it looks like it will do what I want so thank you very much for your help.
So if it helps anyone else, all I had to do was change the form action to point to a cgi function and then I can read the data in that cgi callback. I still have to work out the exact format of the message as it incorporates the filename and content type at the beginning of the actual file data but that should be straight forward.
So in it's simplest form with no checking for the file type etc the html looks like:
<form method=post name=upform action="upload.cgi" enctype="multipart/form-data">
<input type=file name=uploadfile>
<p><input id="Submit" type="submit" value="Submit" /></p>
</form>
The CGI code so far is:
static _mqx_int cgi_upload(HTTPSRV_CGI_REQ_STRUCT* param)
{
HTTPSRV_CGI_RES_STRUCT response = {0};
response.ses_handle = param->ses_handle;
if (param->request_method == HTTPSRV_REQ_POST)
{
char buffer[ 200 ];
uint32_t bufSize = 200;
if (bufSize > param->content_length)
{
bufSize = param->content_length;
}
//Get the POST data into our buffer
uint32_t length = param->content_length;
uint32_t written = 0;
uint32_t read = HTTPSRV_cgi_read( param->ses_handle, buffer, bufSize );
if (read > 0)
{
int fd = -1;
if ((fd = open( "a:\\FTP\\webup.txt", O_WRONLY | O_CREAT | O_TRUNC )) > 0)
{
while ((read > 0) && (length > 0))
{
write( fd, buffer, read );
length -= read;
written += read;
if (length > 0)
{
read = HTTPSRV_cgi_read( param->ses_handle, buffer, (length > bufSize ? bufSize : length) );
}
}
close( fd );
}
}
sprintf( buffer, "Saved %li bytes", written );
return post_OK_response( &response, buffer );
}
return (0);
}
The data saved in the file on the SD card (a:) was:
-----------------------------7e03363290c10
Content-Disposition: form-data; name="uploadfile"; filename="C:\Temp\test.txt"
Content-Type: text/plain
"File Content Here"
-----------------------------7e03363290c10--
So now I just have to work out how to parse the header and footer to save just the file content to the specified file, tidy the code up and add some error checking to the form.
Easy when you know how :-)
Adrian.