title: AWS Pre signed URL
body: <p>I'm Trying to upload image/Video Using PHP / Javascript to AWS S3</p>
  
  <p>this is My PHP Code</p>
  
  <pre><code>&lt;?php
  use Aws\S3\Exception\S3Exception;
  
  
      $filename = isset($_GET['file']) ? $_GET['file'] : '';
      $mime = isset($_GET['mime']) ? $_GET['mime'] : '';
  
      function getSignedUrl($filename, $mime) {
  
  
          require $_SERVER['DOCUMENT_ROOT'].'/ibrainmart/start.php';
  
          $BUCKET = $config['S3']['bucket'];
          $tmp_name = $filename;
  
  
  
          try {
              $command= $S3-&gt;getCommand('PutObject', array(
                      'Bucket'      =&gt; $BUCKET,
                      'Key'         =&gt; $tmp_name,
                      'ContentType' =&gt; $mime,
                      'Body'        =&gt; ''
  
              ));
              $signedUrl = $S3-&gt;createPresignedRequest($command, "1 week");
          } catch (S3Exception $e) {
              echo $e-&gt;getMessage() . "\n";
          }
          echo $signedUrl-&gt;getUri();
          return $signedUrl-&gt;getUri();
      }
  
  
      echo getSignedUrl($filename,$mime);
  
  ?&gt;
  </code></pre>
  
  <p>This my Java Script Code</p>
  
  <pre><code>$(function(){
      // run onLoad
  
      $("#profilePic").uploadHandler("headerupload.php");
  });
  
  // Upload image to S3
  $.fn.uploadHandler = function(s3presignedApiUri) 
  {
      $(document).ready(function (e) {
          $("#profilePic").on('change',(function(e) {
          e.preventDefault();
  
          console.log("ajax going to start..!");
          var fileupload = $('input[name=file]');
          var fileToUpload = fileupload[0].files[0];
             if(fileToUpload !="undefined"){
              var formData = new FormData();
              formData.append("file", fileToUpload);
             }
          console.log("fileToUpload.name"+fileToUpload.name);
          $.ajax({
                  url: s3presignedApiUri, // Url to which the request is send
                  type: "GET",             // Type of request to be send, called as method
  
                  data: 'file='+ fileToUpload.name + '&amp;mime=' + fileToUpload.type , // Data sent to server, a set of key/value pairs (i.e. form fields and values)
  
  
                  cache: false,             // To unable request pages to be cached
                  })       
  
  
                  .done(function(data)   // A function to be called if request succeeds
                  {
  
                      console.log("data ............"+data);
  
                      $.ajax({
                          url : data.url,
                          type : "PUT",
                          data : fileToUpload,
                          cache : false,
                          contentType : fileToUpload.type,
                          processData : false
                      })
                      .done(function() {
  
                          console.info("s3-upload done: "); // REMOVE ME FOR PRODUCTION USE
  
                      })
                      .fail(function(e) {
                          console.error("s3-upload failed",e); // REMOVE ME FOR PRODUCTION USE
                      });
                  })
                  .fail(function(e)
                          {
                          console.log("file passing error.!");
                      })
  
                  }));
  
      });
  
  
  }
  </code></pre>
  
  <p>All these Functions Work Great i guess even after execute it gives me file Upload Successfully Message too.but when  i check s3 nothing is there.</p>
  
  <p>even in console it generate the Presignrd URL too like below.but when i try to Click it it gives me SignatureDoesNotMatch error.(Please Click the URL).what could be the Error..?</p>
  
  <blockquote>
    <p><a href="https://ibrainmartstorage.s3.us-east-2.amazonaws.com/DSC_1595.JPG?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAJZBWQOXKKPC7UXDQ%2F20170824%2Fus-east-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20170824T062933Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=604800&amp;X-Amz-Signature=a4384c737f191c6a516611f67a322ebf98b8e9e0aff65bbcd84e74c87637fb3dhttps://ibrainmartstorage.s3.us-east-2.amazonaws.com/DSC_1595.JPG?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAJZBWQOXKKPC7UXDQ%2F20170824%2Fus-east-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20170824T062933Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=604800&amp;X-Amz-Signature=a4384c737f191c6a516611f67a322ebf98b8e9e0aff65bbcd84e74c87637fb3d" rel="nofollow noreferrer">https://ibrainmartstorage.s3.us-east-2.amazonaws.com/DSC_1595.JPG?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAJZBWQOXKKPC7UXDQ%2F20170824%2Fus-east-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20170824T062933Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=604800&amp;X-Amz-Signature=a4384c737f191c6a516611f67a322ebf98b8e9e0aff65bbcd84e74c87637fb3dhttps://ibrainmartstorage.s3.us-east-2.amazonaws.com/DSC_1595.JPG?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAJZBWQOXKKPC7UXDQ%2F20170824%2Fus-east-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20170824T062933Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=604800&amp;X-Amz-Signature=a4384c737f191c6a516611f67a322ebf98b8e9e0aff65bbcd84e74c87637fb3d</a></p>
  </blockquote>