Wednesday 23 April 2014

Apache, IE8 Download unknown file types

I stumbled upon this issue while configuring a new Adobe CQ5 system. The file in question is an adobe indesign file with an extension .indd. We had this file on our apache server and it worked perfectly on all other browser but IE8 on Windows 7 system. We had to obviously setup Mime type etc first to make sure the server is sending the right headers back to the browser but it will simply say unable to download file in first attempt but will work the next time in IE8.

Well I haven't been able to resolve this completely but have given a work around to our client which is acceptable but not ideal. Obviously if you are in website business you have to get all the solutions on server side as you can't expect all your audience to change there side of things.

Below is what I added to our httpd.conf to fool IE8 in thinking that the file is actually and html file and not an unknown type. The ideal way was to define it as application/octet-stream but IE8 won't buzz because it need to find the association of the file downloaded to save it.

<FilesMatch "\.(indd)$">
ForceType text/html
Header set Cache-Control ""
Header set Pragma ""
Header set Content-Transfer-Encoding "binary"
#Header set Content-Disposition attachment
SetEnvIf REQUEST_URI "/([^/]+)$" FILENAME=$1
Header set Content-Disposition "attachment; filename=\"%{FILENAME}e\"" env=FILENAME
</FilesMatch>

<FilesMatch "\.(indd)$">  bit is to identify my files extension and you will need to replace indd with your extension if you are trying it.
ForceType text/html is the line which is setting the type as an html file which allows multiple extensions

The last two lines in the configuration is there to force file extension which is the only unacceptable bit in the whole solution as Windows 7 will then try an add .htm to the extension and you have to manually remove the extension before saving.
All other browsers are smart enough to not care what you are downloading and they start downloading without a SAVE prompt straight away so you shouldn't have trouble with them.
Also if you can control your users accessing your site then you can just ask them to make an association to a program for the file type and it should download fine after that. Like ask them to try and open and assign say notepad to open such file type. After that if you will try and download then it will download fine.