Go Down

Topic: Arduino webserver --Internet Explorer, no download from download link (Read 525 times) previous topic - next topic

Techno500

Eanple of download link I am using:

Code: [Select]
<!DOCTYPE html>
<html>
<body>

<a href='log.txt' download='log.txt' >Download log.txt</a>

</body>
</html>


This download link works correctly with Firefox and Chrome.  Have tried XP version of Internet Explorer and Windows 8 version of Internet Explorer
both fail to present dialog box for options open file with or save file as.  What happens when clicking download link?  Internet Explorer display lines of
log.txt run from top to bottom of screen.

I have read that, you can force a file to download with php.  An examp;e as applied to this Html example.  Is there any other requirement to use php with Html?

tobyb121

When you get the request for the text file you need to set
Code: [Select]
Content-Type: application/octet-stream
in the HTTP response headers.
Post your code for additional help  ;)

Techno500



@ tobyb121

partial webpage code:

Code: [Select]
client.println("<h2>Collected Observations</h2>");
            client.println("");
            client.print("<a href='log.txt' download='log.txt' >Download log.txt</a>");
client.print("</body>");
            client.println("</html>");
           
          }
          if (StrContains(HTTP_req, "GET /log.txt")) {
            webFile = SD.open("log.txt");
            if (webFile) {
              client.println("HTTP/1.1 200 OK");
      client.println();
            }
          }
          if (webFile) {
            while(webFile.available()) {
              client.write(webFile.read()); // send web page to client
            }
            webFile.close();
          }
          // reset buffer index and all buffer elements to 0
          req_index = 0;
          StrClear(HTTP_req, REQ_BUF_SZ);
          break;
        }


Complete sketch is 700+ lines for "Weather_Data_Logger.ino" and requires an Arduino Mega 2560 due to memory requirements.

Do you need complete sketch?

Thanks for reply,

William

tobyb121

You want your response section to be something like: (I've removed some of the unnecessary logic)
Code: [Select]

webFile = SD.open("log.txt");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/octet-stream");
client.println("Content-Disposition: attachment");
client.print("Content-Length: ");
client.println(webFile.available());
client.println();
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}

This isn't tested but should work, I've added the content length as well, as it helps the browser to know this.

Techno500

@ tobyb121

Thank you; works perfectly -one small change.  A right "}" was missing from removing the logic.
First trial worked right off the bat  :)

Greatly appreciate your help.

William

Go Up