0 votes
1 view
in AWS by (19.2k points)

I'm trying to make it so that my script will show test.jpg in an Amazon S3 bucket through php. Here's what I have so far:


$s3 = new AmazonS3($key, $secret);

$objInfo = $s3->get_object_headers('my_bucket', 'test.jpg');

$obj = $s3->get_object('my_bucket', 'test.jpg', array('headers' => array('content-disposition' => $objInfo->header['_info']['content_type'])));

echo $obj->body;

This just dumps out the file data on the page. I think I need to also send the content-disposition header, which I thought was being done in the get_object() method, but it isn't.

Using this SDK - https://aws.amazon.com/sdk-for-php/

1 Answer

0 votes
by (44.6k points)

Got it to work by echo'ing out the content-type header before echo'ing the $object body.

Echo'ing the content-type header before $object body will give the result. Do something like this:

$objInfo = $s3->get_object_headers('my_bucket', 'test.jpg');

$obj = $s3->get_object('my_bucket', 'test.jpg');

header('Content-type: ' . $objInfo->header['_info']['content_type']);

echo $obj->body;

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !