Amazon S3 and Internet Explorer

24 Apr 2006

If you're using Amazon's excellent S3 service (like we are) you may want to post up an executable at some point. If you're using the Ruby API, you'll find that when folks using Internet Explorer try to download the file, the MIME type won't be set and they'll get a browser full of gibberish. Here's the secret sauce to make the "save this file" dialog box pop up properly:

name = "filename.exe"
c = S3::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, false)
bytes = nil
File.open(name, "rb") {|f| bytes = f.read } 
options =  { 
  'Content-Type' => 'application/octet-stream', 
  'Content-Disposition' => 'attachment; filename="' + name + '"' 
}
c.put(MY_BUCKET, name, bytes, options )

So, two HTTP headers should be set: Content-Type and Content-Disposition. The header name case seems to be important too.