htmliframemime-types

How to force mime-type of file download


When users visit our website's download page, it automatically starts the download. The page has a display:hidden iframe with src pointing to the installer file:

<iframe src="/path/to/installer.dmg"></iframe>

This works fine so far. But my Chrome extension: "Web developer" logs this Warning message

Resource interpreted as Document but transferred with MIME type application/octet-stream

So, is there a way to explicitly declare installer.dmg's content-type as octet-stream, so that browsers do not get confused?


Solution

  • As one of the previous answers references a broken link I will give my answer here.

    If you are trying to specify the mime type of files with a certain extension you can add this to .htaccess:

    AddType application/octet-stream .dmg
    

    However, this will not guarantee that browsers will 'download' the file. Chrome for example does not recognise this. So here is a way to force files of a certain type to 'download':

    <FilesMatch "\.(?i:dmg)$">
      ForceType application/octet-stream
      Header set Content-Disposition attachment
    </FilesMatch>
    

    The little bit of regex around the extension (DMG) is just there to make it case insensitive.

    You might need to clear browser cache before it works correctly.

    This works in the latest Chrome, Firefox and Internet Explorer 8 (as of August 2013). I have not tested in the latest Internet Explorer or Safari, so if someone has those browsers and can test them, please confirm they work in the comments below.