Author Topic: Web binary file download  (Read 4476 times)

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Web binary file download
« on: October 24, 2007, 03:38:08 PM »
Hi, I'm going to store some NV params in a file, Z.BIN, which our application can save and load on bootup. I'm using a file instead of the paramter block because it would require less hacking into the code when
services packs etc are released. We can download this file via Firefox 2.0
and save it on the PC. It pops up a "Save as" box when it determines it's
a binary file.  I was looking at the Ethereal trace and it doesn't look like the web server sends HTP headers describing the file, so Firefox must determine this by the extension or maybe it looks at the file contents. When we do a software update we can then FTP the paramater file back up to the unit.
 When I tested this on IE 6.0 ,it doesn't pop up a "Save as" box, but just dumps this on the screen. I added a binary header to the start of the file,
thinking maybe IE analyzes the file to determine what to do with it, but
it still just dumps it. I then added HTP headers

"Content Type: application/octet-stream\r\nContent-Type: application/force-download\r\n\Content-Length=2048\r\nContent-Transfer-Encoding: binary\r\nContent-Disposition: attachment\r\n\r\n"

 to the beginning of the file, but IE still doesn't pop a "Save as" box. I can see the header in Ethereal, so they're getting out on the line.
Is this a IE issue ? I googled around and they suggest adding the above
header to force IE to save the file. IE doesn't seem to have any settings
to tell it what to do with MIME type of application/octet stream.

 Anyone have any ideas on this ?


 Monitoring an Appache web server and accessing a .bin file on it, I notice
that it sends down an HTTP header file in a sperate packet containing

HTTP/1.1 304 Not Modified
Date: Wed, 24 Oct 2007 20:28:16 GMT
Server: Apache/2.2.3 (Debian) mod_python/3.2.10 Python/2.4.4 PHP/5.2.0-8 mod_ssl/2.2.3 OpenSSL/0.9.8c
Connection: Keep-Alive
Keep-Alive: timeout=15, max=84

 IE doesn't know what kind of file it is and pops up the "Save As" box.
It seems like IE will interpret a file as text/HTML if it has no header and
the HTTP header must be in a seperate frame from the actual data.

 Thanks,
 John


« Last Edit: October 24, 2007, 09:34:20 PM by johnr »

Offline Thomas

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Web binary file download
« Reply #1 on: October 25, 2007, 03:15:04 PM »
You have a link to the parameter file, right? You should probably add "type= application/octet-stream" in the link. <a href="parameters.bin" type= application/octet-stream" ... so the browswer knows what to expect.

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Web binary file download
« Reply #2 on: October 29, 2007, 03:32:47 PM »
Thomas. I've been sidetracked for a few days. I tried putting the
"Content Type: application/octet-stream"  etc in the <HEAD> section of the page using the meta  HTTP equiv and in the <A HEF ...> tag in the link, but IE 6 does not care and just
displays the file. It works with FireFox 2.


 Thanks,
 John

Offline Thomas

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Web binary file download
« Reply #3 on: January 08, 2008, 10:52:56 AM »
I had to get this working myself so I digged around a little and found that you need to append a header to the file you want to transmit to tell the browser to raise the "save as" dialog. Try adding the following header before the filecontent:

Code: [Select]
HTTP/1.0 200\r\nContent-Type: application/octet-stream\r\nContent-disposition: attachment; filename=filname.ext\r\n\r\n
(filedata...)

The "attachment" keyword is what tells the browser to raise the dialog. "filename.ext" can be any filename that you want to appear as default for the file in the save-as dialog.

To test this just add the header to a file before you upload it to uTasker.

This makes it work in all browsers. Seems that IE and opera still try to determine the fileformat and extension even if you specify the content type though.

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Web binary file download
« Reply #4 on: January 08, 2008, 08:51:59 PM »
Thomas , thanks for the help. I tried all kinds of headers
with no luck with IE . Next time I get into this I'll try this out.

 John