Reputation:
I want to do the following:
The file exsists in the S3 and can be reached with an browser.
Step one is already done with the following:
try{
$result = $client->getObject(array(
'Bucket' => $bucket,
'Key' => $filename
));
} catch (Exception $e) { //ERROR
echo($e->getMessage());// FOR THE ERROR
}
I use the $result['Body'] to get the image.
Note: the server is an EC2 instance so the password is already done with an role from IAM
Step two:
image_array=[image1,sound1,sound2,image2];
echo json_encode(image_array);
This step is giving me an empty array. I understand that it is empty because of the encoding. The images are binary data objects and will not work fine with the JSON. But what is the right way? Should I do something like
image_array=[json_encode(image1),etc.];
Or should I do something like this
image_array=[utf8_encode(image1),etc];
Question: How am I supposed to give the image back in an JSON code so I won't break and is readable?
Note: I use this to give info back to the client something similar to this
total_array=[ [image1,property1,property2],
[image2,property1,property2],
[image3,property1,property2],
];
Upvotes: 0
Views: 1743
Reputation: 86
I have used base64_encode to transfer image data before.
base64_encode($image);
Upvotes: 1