@ andre.m -
I have tried my codes many times again, and I have 2 questions. The test C# codes and html codes are as follow:
C# codes:
using (HttpServer server = new HttpServer())
{
server.AddEvent("/fileupload", new HttpServer.EventCallback(File_Upload));
server.AddEvent("/upload", new HttpServer.EventCallback(uploadPage));
while (true)
{
// Sleep for 500 milliseconds
Thread.Sleep(500);
}
}
private static void File_Upload(object sender, HttpServer.EventCallbackEventArgs e)
{
e.Response = Resources.GetString(Resources.StringResources.FileUpLoad);
e.ResponseContentType = "text/html";
}
private static void uploadPage(object sender, HttpServer.EventCallbackEventArgs e)
{
if ((e.Post != null) && (e.Post["Config"] != null))
{
e.Response = "You have uploaded the following text file: <br />";
e.Response += ((HttpServer.MultiPartItem)e.Post["Config"]).Content;
}
else
{
e.Response = "No data posted";
}
e.ResponseContentType = "text/html";
}
FileUpLoad.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>File upload in HTML forms</title>
</head>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<p>
Please specify Config.hex file<br>
<input type="file" name="Config" size="100">
</p>
<div>
<input type="submit" value="Upload">
</div>
</form>
</body>
</html>
Question 1: How can I upload .hex file?
I have tested uploading Config.txt and Config.hex files, and the content of these files are same, olny the type of file is different.
If I upload Config.txt, I can see the content of these file in the webpage “/upload” after clicking “upload” buttom(see picture 1 and 2). I can use “…Content.ToString();” to get the string of content and save them into SD card for IFU.
If I upload Config.hex, I can’t see the content of these file in the webpage “/upload” after clicking “upload” buttom, I can only see “System.Byte[]” in the webpage “/upload” (see picture 3), I don’t know how can I get the string of content and save them into SD card for IFU.
Question 2: How can I upload big file (for example: Firmware.hex is 1,29 MB (1.352.832 bytes)?
In Question 1 I have tested only a small file Config.hex, and the Config.hex is 6,80 KB (6.968 bytes), It seems that no problem to upload about 10KB file.
I had some steps to test the Firmware.txt.
step1: After “F5” my project I open webpage, choose Firmware.txt and clik uploading buttom. I can see something from Visual Studio Output (see picture 4).
I found that “Post data exceeds maximum allowed size” from Visual Studio debug.
step 2: I found the define “POST_MULTIPART_MAX_SIZE” in HttpServer.cs and changed the size to “100*131072”, It seems that the size is big enough for Firmware.txt
see as follow, I have changed the “POST_MULTIPART_MAX_SIZE”:
in HttpServer.cs
private const int POST_URLENCODED_MAX_SIZE = 4096; // Maximum buffer size to use when receiving UrlEncoded POST requests
private const int POST_MULTIPART_PAYLOAD_SIZE = 1024; // Block size to use when receiving MultiPart POST requests
private const int POST_MULTIPART_MAX_SIZE = 100*131072; // Maximum buffer size to use when receving MultiPart POST requests
step 3: I test again like step 1. I found the new problem “Exception System.OutOfMemoryException”. (see picture 5)
I have also tried some differnt small “POST_MULTIPART_MAX_SIZE”, for example: “50131072", "25131072”, and “15*131072”. there is always the “System.OutOfMemoryException” problem…