Go Down

Topic: How to put log file to download when accessed with browser (Read 1 time) previous topic - next topic


Hello, i'm trying to serve the log file, to be downloaded, but i don't know how to do it. I put in my code to when arduino gets something like GET /logfile  it opens the file and does a client.print of the file. But this opens a new page with the information of the logfile, but i prefer the client stay on the main page, and simply get de downloaded logfile. Thanks in advance!


something like when we download a file from web, we click on file and it starts to download it. For my project, this file it's the log file created by arduino, stored on sd card, and i'm trying to provide it to be downloaded and not to be visualized directly on browser (like client.print does).


Feb 24, 2013, 11:05 pm Last Edit: Feb 24, 2013, 11:07 pm by SurferTim Reason: 1
Normally when you do that, you are using FTP. I'm not sure how this will run if compiled for an Uno. I use a Mega2560.
Note it has the same 64 byte buffer as in the other thread.

edit: Due to the fact you need two sockets open simultaneously for a FTP server, I can only provide client code.


To cause the browser to download a file instead of rendering it, you must set the "Content Disposition" header in the reply headers that you client.print() for the /layout case:

Code: [Select]

    Content-Disposition: attachment; filename=example.txt;

With the appropriate filename, of course.

The next line after sending the "Content-Type" header is the usual place.




@billroy: Thanks for that tip. I never paid attention to why sometimes a browser will display a pdf doc, and other times download it. I'm going to try that, and if it works, you will get a karma boost.  :)

Go Up