title: Upload base64 image to amazon s3
body: <p>I'm having some issues when trying to upload an image to AWS S3. It seems to upload the file correctly but, whenever I try to download or preview, it can't be opened. Currently, this is the upload code I'm using:</p>
  
  <pre><code>&lt;?php
  require_once 'classes/amazon.php';
  require_once 'includes/aws/aws-autoloader.php';
  use Aws\S3\S3Client;
  
  $putdata = file_get_contents("php://input");
  $request = json_decode($putdata);
  
  $image_parts = explode(";base64,", $request-&gt;image);
  $image_type_aux = explode("image/", $image_parts[0]);
  $image_type = $image_type_aux[1];
  $image_base64 = $image_parts[1];
  
  $dateTime = new DateTime();
  $fileName = $dateTime-&gt;getTimestamp() . "." . $image_type;  
  
  $s3Client = S3Client::factory(array(
      'region' =&gt; 'eu-west-1',
      'version' =&gt; '2006-03-01',
      'credentials' =&gt; array(
          'key'    =&gt; Amazon::getAccessKey(),
          'secret' =&gt; Amazon::getSecretKey(),
      )
  ));
  
  try {
      $result = $s3Client-&gt;putObject(array(
          'Bucket'          =&gt; Amazon::getBucket(),
          'Key'             =&gt; 'banners/' . $fileName,
          'Body'            =&gt; $image_base64,
          'ContentType'     =&gt; 'image/' . $image_type,
          'ACL'             =&gt; 'public-read'
      ));
      echo $result['ObjectURL'] . "\n";
  } catch(S3Exception $e) {
      echo $e-&gt;getMessage() . "\n";
  }
  ?&gt;
  </code></pre>
  
  <p>So, when I check the console after uploading the image file, it has the expected size, permissions and headers but, as I said, whenever I try to open the file, it fails.</p>
  
  <p>What could be the problem here? Thanks in advance.</p>