dimanche 1 février 2015

base64 Image Post to AWS async call

Having a small issue when posting a base64 image to AWS.


Using the following sites How to save a HTML5 Canvas as Image on a server - The accepted answer


and http://ift.tt/1CQETny


I have the cropped image I'm sending posting correctly with just the above code.


However, integrating into an aws upload has caused an issue. The upload is goes through (uploads the file to aws) but its doesn't seem to have time to fully complete the crop



define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';


$resizedJpegData = '../temp/' . $file;

$result = $uploadClient->putObject(array(
'Bucket' => 'bucketname',
'Key' => $fileName,
'Body' => fopen($file, 'r+'),
'ACL' => 'public-read',
'ContentType' => $_FILES['image_file']['type'],
'StorageClass' => 'STANDARD'
));

$url = $result['ObjectURL'] != '' ? $result['ObjectURL'] : 'NULL';

if ($url != null) {
$logoUpload = $client->updateItem(array(
"TableName" => "TableName",
"Key" => array(
"TenantID" => array(
Type::NUMBER => $_SESSION['tid']
),
),
"AttributeUpdates" => array(
"Logo" => array(
"Action" => "PUT",
"Value" => array(
Type::STRING => $url
)
)
)
));
}


The image pre-croppedUploaded photo


If its just the post from http://ift.tt/1CQETny it goes through correctly. issue seems to be with the aws upload part


1 commentaire: