PHP/AWS S3 rookie here: working on a project where I need to be able to display both an album artwork from AWS S3 bucket as well as play a music file. I can upload, but when trying to view image, it downloads instead. Have checked the content-type and content disposition. I believe the problem is around this snippet of code: I would appreciate any help/suggestions.
<?php
....
....
try {
$s3 = S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
),
'version' => 'latest',
'region' => 'us-east-2'
)
);
//
$result = $s3->getObject(array(
'Bucket' => $BUCKET_NAME,
'Key' => $keyPath
));
echo $result;
//exit();
// Display it in the browser
header("Content-Type: {$result['ContentType']}");
header('Content-Disposition: filename="' . basename($keyPath) . '"');
return $result['Body'];
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html>
<head>
<title>display image</title>
</head>
<body>
<img src="<?php echo $result['body']; ?>">
</body>
</html>