Pages: [1]   Go Down
Author Topic: How to put log file to download when accessed with browser  (Read 697 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
http://playground.arduino.cc/Code/FTP
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.
« Last Edit: February 24, 2013, 05:07:47 pm by SurferTim » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    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.

-br
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so simple like that   smiley-red  thanks a lot!!!!
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.  smiley
Logged

Pages: [1]   Go Up
Jump to: