PDFs in Amazon S3 don't open in Chrome for view PDFs in Amazon S3 don't open in Chrome for view google-chrome google-chrome

PDFs in Amazon S3 don't open in Chrome for view


If you want the browser to treat the file as pdf you should let him know that his file is a pdf. The way to do so is to send the relevant header:

Content-type: application/pdf

The current header that is sent by s3 is:

Content-type: application/octet-stream

Since you upload the files to s3 - you can either set the correct mime-type for the file during uploading or afterward, using some of the s3 tools (for example s3cmd for windows).

According to the link to the documentation you provided, the putObjectFile function is deprecated, but this is the definition:

putObjectFile (string $file, string $bucket, string $uri, [constant $acl = S3::ACL_PRIVATE], [array $metaHeaders = array()], [string $contentType = null])

As you can see - the last parameter is contentType - so you can set it to application/pdf when uploading the file.
This will set the correct header when downloading.