MKR 1010 uploading client file to Arudino-hosted server

I'm using an MKR 1010 Wifi as a server for a web page. The client is using a Chrome browser running on a Fedora Linux workstation that's on the same WiFi network the MKR 1010 is on--I just bang "http://arduino" (DNS-reserved to 192.168.1.19) into the browser URL and the MKR-generated page appears, the buttons all do the right things, etc.

What I need to do is send the contents of a file from the Fedora-based client to the Arduino-based server. I'm a total amateur at HTML/Javascript/etc, but I found examples of code that put an "Upload" button on the screen and the button seems to work: it pops up a file-select window and accepts my choice.

But where is the data going? If anywhere? I see on the serial monitor the result of the HTML POST that happens when the upload submit button is clicked, but the 8 bytes of ASCII data in my sample file isn't there.

Any help would be appreciated.

Thanks,
Chris Moller

You did something wrong. As you're hiding your code from us we cannot tell you what you did wrong. My (wild) guess is a wrong enctype.

Yeah, I kinda figured I was doing something wrong.

The relevant Arduino code is this, cut'n'pasted verbatim from stackoverflow:

client.println ("<form id=\"uploadbanner\" enctype=\"multipart/form-data\" method=\"post\" action=\"#\">"); 
client.println ("  <input id=\"fileupload\" name=\"myfile\" type=\"file\" />"); 
client.println ("  <input type=\"submit\" value=\"submit\" id=\"submit\" />");
client.println ("</form>");

This pops up a file-select window and, when I hit "submit," sends the following:

POST / HTTP/1.1
Host: arduino
Connection: keep-alive
Content-Length: 194
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http: arduino
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryCRB3Oph5C2m7QZq6
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/
537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8
Sec-GPC: 1
Accept-Language: en-GB,en
Referer: http: arduino/
Accept-Encoding: gzip, deflate
GET /favicon.ico HTTP/1.1
Host: arduino
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/
537.36
Accept: image/avif,image/webp,image/apng,image/svg+xml,image/,/*;q=0.8
Sec-GPC: 1
Accept-Language: en-GB,en
Referer: http: arduino/
Accept-Encoding: gzip, deflate

If I change the "post" to a "get," I get:

GET /?myfile=mydata.txt HTTP/1.1
Host: arduino
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8
Sec-GPC: 1
Accept-Language: en-GB,en
Referer: http://arduino/
Accept-Encoding: gzip, deflate
GET /favicon.ico HTTP/1.1
Host: arduino
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Accept: image/avif,image/webp,image/apng,image/svg+xml,image/,/*;q=0.8
Sec-GPC: 1
Accept-Language: en-GB,en
Referer: http: arduino/?myfile=mydata.txt
Accept-Encoding: gzip, deflate

(I've had to edit a few lines that looked like links...)

The first line of which at least shows the name of the file I'm after, but in no case, so far as I can tell, am I getting the contents of the file.

That are only the header lines. As you still didn't post your (complete) code we cannot tell you how to fix that.

You cannot transfer a file using an HTTP GET.

"As you still didn't post your (complete) code we cannot tell you how to fix that."

My "complete code" is about 780 lines long. No good way to post that. My intent was to provide just the relevant lines.

And, anyway, I've worked around this issue.

You can attach a file if the editor doesn't allow that much code (although I think it should be no problem).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.