Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2024, 01:06:36 13:06


Login with username, password and session length


Pages: [1]
Print
Author Topic: Internet Explorer force download rather than open a file  (Read 7961 times)
0 Members and 2 Guests are viewing this topic.
Vineyards
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 64
-Receive: 37


« on: May 31, 2015, 12:11:38 00:11 »

Anyone having an idea about above. I tried all the suggestions I could find on the net but it is a no go.
It is an Arduino based product and I can get browsers like Chrome and Firefox to work as intended but when it comes to Internet Explorer it doesn't work. It just shows the contents of the file in the browser screen.

Do you have any suggestions?
Logged
geconom
Junior Member
**
Offline Offline

Posts: 92

Thank You
-Given: 89
-Receive: 18


« Reply #1 on: June 01, 2015, 10:54:14 10:54 »

I do not get it. You want to run Chrome, Firefox and IE on Arduino? Which OS?
Logged
snowman
Junior Member
**
Offline Offline

Posts: 78

Thank You
-Given: 181
-Receive: 53


« Reply #2 on: June 01, 2015, 08:14:17 20:14 »

usually if a browser shows content instead of downloading or opening, it means content type header is wrong. for example if you want to send a zip file from server to client and server code does not set headers correctly, browser shows inside of the zip file which is rubbish to humen eye.

please search stackoverflow for article number 386845.

best.
Logged
cadence
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 103
-Receive: 430



« Reply #3 on: June 01, 2015, 09:06:26 21:06 »

You haven't said whether the website is yours and which file type IE is showing rather than downloading.  

However, assuming that the website is yours, create a text file named .htaccess in the root directory of the website. Include in that text file an AddType directive for each of the the filetypes you want to force to download, for example:

AddType application/octet-stream .zip
AddType application/octet-stream .mov
AddType application/octet-stream .pdf

Those file types should now download in all browsers rather than open.
 
Google: .htaccess force file download AddType  for more info and articles and a list of valid MIME types.
Logged
Vineyards
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 64
-Receive: 37


« Reply #4 on: June 01, 2015, 11:24:14 23:24 »

Thanks for the answers. I have already written this is an Arduino based server which means it doesn't run Apache. I have this problem with just two browser. All the others work as intended. There seems to be nothing wrong with the headers and there is no builtin interface to htaccess. I think I need a registry pathch that will tell explorer to not try to open a csv file and download it as an attachment instead. If the headers were faulty, other browsers would not work either.
Logged
cadence
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 103
-Receive: 430



« Reply #5 on: June 02, 2015, 04:51:27 04:51 »

Ah 'Arduino server' - that was the missing piece of the puzzle.

The headers aren't 'faulty', it's just that IE strictly adheres to the standards whereas Chrome and Firefox don't and they download some MIME types by default.

Try looking at the 'Content-Disposition' HTTP header response field which forces a file download dialog in compliant browsers like IE.
Logged
Vineyards
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 64
-Receive: 37


« Reply #6 on: June 02, 2015, 09:30:56 21:30 »

I am normally a PIC guy but this Project came in and I had to learn Arduino from scratch which felt like doing 180km/h but on somebody else's car.
I tried the content-disposition stuff but it did not make much difference. I am trying to find out what went wrong using the developer debug consoles of ie and the others.
Logged
cadence
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 103
-Receive: 430



« Reply #7 on: June 03, 2015, 06:04:45 18:04 »

I'm a PIC person too and as such I've never really had the need or desire to look into Arduino.

You may have seen it already but there's an interesting article - Google: 'ethernet-shield-web-server-tutorial', on the startingelectronics_dot_com site.

It seems to be very thorough and returns data using AJAX and XML.
« Last Edit: June 04, 2015, 03:19:13 15:19 by cadence » Logged
Vineyards
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 64
-Receive: 37


« Reply #8 on: June 04, 2015, 09:05:20 09:05 »

I have seen that one but I will take another look. It is not easy to implement a full-fledged server on an Arduino hence some annoying limitations.
Logged
WolfPack
Inactive

Offline Offline

Posts: 2

Thank You
-Given: 20
-Receive: 0


« Reply #9 on: June 14, 2015, 06:41:58 18:41 »

Hi.

cadence is right. The way to force any browser to download a file is by using the HTTP header field "Content-Disposition: attachment;". You should take into account that the order of the header fields is extremely important, i.e. your script will work in newer versions of I.E. but not in older ones (such as IE 7). Before this field, I'd recommend you to send also content-type one to notify the mime type of the file that the client is about to download. As an example, you would use "Content-Type: application/pdf" for a PDF file, or "Content-Type: text/csv" for a CSV one.

If you have a look at http://www.arduino.cc/en/pmwiki.php?n=Tutorial/WebServer:
Code:
if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");

As you see in this example, the code first sends the HTTP version and status code, then the headers, and then the content. You should use, then, something like this:
Code:
if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Disposition: attachment; filename=\"myfile.csv\";");
          client.println("Content-Type: text/csv");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println();
          //Print the contents of the file

You've got an example about reading a csv content from a SD card in this page: http://forum.arduino.cc/index.php?topic=141418.0.
Anyway, I've never used Arduino as a web server. I always prefer using a Raspberry PI and then coding the project in PHP, or even using a PIC32 with the MLA libraries, rather than coding a complete web application for an Arduino board.
« Last Edit: June 14, 2015, 06:48:33 18:48 by WolfPack » Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC