Adding Content-Type & Expires Headers to S3 Assets
When served via HTTP the response headers for your asset will look something like the following:
HTTP/1.1 200 OK Server: AmazonS3 Content-Type: application/octet-stream Connection: close Last-Modified: Fri, 24 Mar 2017 20:07:44 GMT x-amz-request-id: 5C5D94EED7CCB23A Accept-Ranges: bytes Date: Tue, 28 Mar 2017 03:49:48 GMT x-amz-id-2: wsLQxHsmlv07jZd4dzV2LJmRXa1BMNfSSepkeYTrYG2XGALVWm96QdWMmuSClOvDwGybQpfeAow= Content-Length: 128259 Etag: "afe335175aec1bfc26a6cd3a4dba6819"
Two important HTTP headers are missing for your asset:
Content-Type, which tells your browser how to parse & interpret the response, and
Expires, which tells your browser how long to cache the asset for.
Luckily – though not entirely clear from the documenation – these shortcomings can be easily overcome when uploading the file by providing the necessary key/value pairs when uploading:
(The mime-type for a file is being set via rmr-lib.)
Inspecting the response for a
GET request uploaded with the
Expires key/value pairs verifies that the necessary headers are being sent along with the asset:
HTTP/1.1 200 OK … Content-Type: image/png Expires: Fri, 07 Apr 2017 03:00:23 GMT …