아마존 S3에서 이미지 파일을 가져 오기위한 PHP 스크립트가 있습니다. <img src="test.php">
이미지를 잘 나타내려면 test.php
이라고 입력하면됩니다.S3 이미지 파일에 대한 게시물 요청
그러나 요청을 가져 와서 이미지의 SRC를 설정하려고하면 올바르게 표시되지 않습니다. 결국이 게시물을 사용하여 params를 전달하고 싶습니다. src
을 검사 할 때 헤더 ("Content-type : image")가 설정되지 않은 것처럼 메타 데이터로 채워집니다.
$.get("test.php",function(data) {
$('#image1').attr('src', data);
});
내 test.php 스크립트 :
require '../vendor/autoload.php';
use Aws\S3\S3Client;
$region = 'us-west-2';
$bucket = 'mybucket';
$key = 'mykey';
$secret = 'mysecret';
$s3Client = new S3Client([
'version' => 'latest',
'region' => $region,
'credentials' => [
'key' => $key,
'secret' => $secret,
],
]);
$result = $s3Client->getObject(array(
'Bucket' => $bucket,
'Key' => 'monkey1.jpg'
));
header("Content-type: image");
// Print the body of the result by indexing into the result object.
echo $result['Body'];
//echo '<img src="'.$result['Body'].'">'