How to change file content type of AWS s3 bucket before uploading in PHP
<p>I have the following code that allows me to successfully upload files to my S3 bucket. </p>
<pre class="brush:php;toolbar:false;">$keyName = 'test_example/' . basename($_FILES["fileToUpload"]['tmp_name']);
$pathInS3 = 'https://s3.eu-west-2.amazonaws.com/' . $bucketName . '/' . $keyName;
//Add it to S3
try {
$s3->putObject(
array(
'Bucket'=>$bucketName,
'Key' => $keyName,
'contentType' => 'image/png',
'SourceFile' => $keyName,
'StorageClass' => 'REDUCED_REDUNDANCY'
)
);
} catch (S3Exception $e) {
die('Error:' . $e->getMessage());
} catch (Exception $e) {
die('Error:' . $e->getMessage());
}</pre>
<p>The problem is that they download instead of displaying the image. I've looked around and tried adding: 'contentType' => 'image/png' and this doesn't change anything. The file is still uploaded as a Value application/octet-stream rather than a Jpg image. Is there a way to change this? </p>