dimanche 29 mars 2015

image loading into DynamoDB using: PHP, Ubuntu, EC2 Amazon Web Services

I'm trying trying to load an image provided trough an HTML form into a Dynamo Db table.


I'm hard coding the image loading part, but later I want to uncomment:



$con=file_get_contents( basename($_FILES["fileToUpload"]["name"]) );


And upload any image into DynamoDB.


This is the html file:



<form action="upload-download-dynamodb.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>


This is the upload-download-dynamodb.php



<?php

// Convert image to binary

//$con=file_get_contents( basename($_FILES["fileToUpload"]["name"]) );

$con=file_get_contents("Tuan.jpg");
$en=base64_encode($con);
$mime='image/gif';
$binary_data='data:' . $mime . ';base64,' . $en ;

?>
<img src="<?php echo $binary_data; ?>" alt="Test">
<?php

// Connect to Dynamodb

require './awssdkphp/aws-autoloader.php';
use Aws\DynamoDb\DynamoDbClient;

$client = DynamoDbClient::factory(array(
'profile' => 'default',
'region' => 'us-east-1' // replace with your desired region
));

// Put item inside a table

$responsePut = $client->putItem(array(
'TableName' => 'saleItems',
'Item' => array(
'itemID' => array('N' => 11 ), // Primary
'picture' => array('B' => openssl_random_pseudo_bytes(5)),
'array' => array('S' => $en),
'description' => array ('S' => "picture description" )
)

));

?>


The "upload-download-dynamodb.php" code works fine if I run it in the terminal(e.i. php upload-download-dynamodb.php). Buy if I execute the "upload-download-dynamodb.php on the browser(Firefox), the image is displayed but the data is not uploaded into the 'saleItems' table in Dynamo DB.


Any ideas of why the "upload-download-dynamodb.php" code loads the picture into Dynamo DB when I execute it through the terminal but not when I execute it in the browser(Clicking the refresh button)?


BTW, I gave full permissions to upload-download-dynamodb.html ,upload-download-dynamodb.php and Tuan.jpg.


Aucun commentaire:

Enregistrer un commentaire