Simple HTTP-Webserver

Status
Not open for further replies.

Welocs

Well-known member
Hello,

i want to build a simple Web-Server on the Teensy 3.5.
I can successfully send my content, e.g. .css, .html, etc. files over Ethernet to a webbroswer from a SD-Card.
But trying to upload data to the teensy doesn't work over html. Seems, like the browser just doesn't upload the files.
I'd like to upload some data over a browser to simply update files on a SD-Card.

i am using pauls ethernet library for data transfer.
the html-code for uploading is e.g. this:
Code:
            <form method="POST" enctype="multipart/form-data" action="">
                <div class="form-group">
                    <hr />
                    <label for="exampleInputFile">File input</label>
                    <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
                    <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
                    <button type="submit" class="btn btn-primary">Submit</button>
                </div>
            </form>
-----------------------
my reading code, just to monitor the incomming data is this:
Code:
EthernetClient client;

void htmlServer() {
	// listen for incoming clients
	static uint32_t numberClient = 0;
	static unsigned long timeStamp;
	unsigned long timeout;
	static boolean isTimeout = false;
	client = server.available();
	if (client) {
		htmlServerClientRead(numberClient);
		numberClient++;
		timeStamp = millis();	// reset timeout;
		isTimeout = false;
	}
	timeout = millis() - timeStamp;
	if ((timeout > 2000) && !isTimeout) {	// reset numberClient after 2 seconds
		Serial.print("---timeout---\n\n\n");
		numberClient = 0;
		isTimeout = true;
	}
}

void htmlServerClientRead(uint32_t numberClient) {
	boolean trasmissionDone = false;

	#ifdef htmlServerMsg
	Serial.println("new client");
	#endif // htmlServerMsg
	while (client.connected()) {
		if (client.available()) {
			Serial.write(client.read());

		}
	}
	delay(1);
	// close the connection:
	Serial.print("Closing conntection...\n");
	client.stop();
	#ifdef htmlServerMsg
	Serial.println("client disconnected");
	#endif // htmlServerMsg
}
----------------------------
the result in the serial monior is this:
CHROME:
Code:
new client
POST /html/index.html HTTP/1.1
Host: 192.168.0.31
Connection: keep-alive
Content-Length: 44
Cache-Control: max-age=0
Origin: http://192.168.0.31
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary6j0B6fY22Ij7A4Bb
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://192.168.0.31/html/index.html
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

------WebKitFormBoundary6j0B6fY22Ij7A4Bb--
Closing conntection...
client disconnected
---timeout---

Question:
when selecting a file (e.g a simple .txt file) in the browser an hitting the "submit" button, as shown, no data is uploaded through firefox.
Can some help me with this issue please? =(

Greetings,
Welcos
 
try to upload a file with .html extension.
the ending of a file doesn't change the content of a file - it just tells a machine how to interpret it. By the fact that you can upload any files on several servers as .mp3, .txt, .png, .jpg ect., i won't think trying out .html ending would help.

The simple solution for this problem was, that in the HTML-Tags the attribute "name" was missing.
-> if a HTML object doesn't have a name in it, a browser (in my case firefox and chrome) will not send its content.
so if you e.g create a form with many checkboxes, textfields or similar stuff, the browser will send only the data of these, which got a name:
Code:
<input type="text" value="text default">                      // the browser won't send any data of this input - but the textfield will be displayed in your browser
<input type="text" name="text1" value="text default">   // the browser will send the data "text default" associated to name "text1" in the body of HTTP, after clicking the "submit" button
<input type="file" name="myfile" value="">                   //  the browser will send the content of a file selected by the user - associated to name "myfile" in the body of HTTP, after clicking the "submit" button

if someone wants to know, how a request like this lookes like, just ask me, or google for it :)

greetings welocs
 
Status
Not open for further replies.
Back
Top