Forcing Download from s3 amazon servers Forcing Download from s3 amazon servers codeigniter codeigniter

Forcing Download from s3 amazon servers


You just need to set the correct headers on your files in S3 in order to force the browser to download rather than opening the file. Set these:

Content-Disposition: attachment; filename=FILENAME.EXTContent-Type: application/octet-stream

You will need to set them when uploading the files to S3. With the php SDK you'd use create_object.

Or you can set these after uploading using 'change_content_type' or by copying the file to itself in S3 and setting the correct headers.


Bit late to the party, but often times with a file you don't want to have to decide at storage time how it will be used. You want to be able to store the file once, then in one area possibly embed the file or display in browser, and in another area enable the user to download the same file.

Fortunately you can do that by providing override parameters in the request url. It only works with signed requests, but thankfully you're already doing that.

If you add a parameter like &request-content-type="application/force-download" that should do the trick.

Check out the Request Parameters section of the S3 GET Object documentation:http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html


The question is about setting this programmatically, but to do so manually through the AWS console:

  • Select a file in S3.
  • Properties > Metadata > Add more metadata
  • Key: Content-Disposition Value: Attachment
  • Save