title: Amazon S3 Upload error PermanentRedirectException
body: <p>I've installed the Amazon SDK for PHP using composer. I copied the example code and implemented into my system, but when I attempt to upload a file, I'm getting the following (i've made the paths generic for security):</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'Aws\S3\Exception\PermanentRedirectException' with message 'Encountered a permanent redirect while requesting <a href="https://s3.amazonaws.com/mybucket/path/to/image.jpg" rel="nofollow">https://s3.amazonaws.com/mybucket/path/to/image.jpg</a>. Are you sure you are using the correct region for this bucket?' in /path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php:49 Stack trace: #0 /path/to/vendor/guzzlehttp/promises/src/Promise.php(199): Aws\S3\PermanentRedirectMiddleware->Aws\S3{closure}(Object(Aws\Result)) #1 /path/to/vendor/guzzlehttp/promises/src/Promise.php(152): GuzzleHttp\Promise\Promise::callHandler(1, Object(Aws\Result), Array) #2 /path/to/vendor/guzzlehttp/promises/src/TaskQueue.php(60): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}() #3 /path/to/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(96): GuzzleHttp\Promise\TaskQueue->run() #4 /path/to/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(123): Gu in /path/to/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php on line 49</p>
  </blockquote>
  
  <p>In my composer.json I'm specifying the 3.1 Amazon SDK.</p>
  
  <p>In my PHP I'm doing the following (based on several image files posted to the script):</p>
  
  <pre><code>require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
  
  use Aws\Credentials\Credentials;
  use Aws\S3\S3Client;
  use Aws\S3\Exception\S3Exception;
  
  $credentials = new Credentials('my-accessKey', 'accessSecret');
  
  try {
      $s3Client = S3Client::factory(array(
          'credentials' =&gt; $credentials,
          'region' =&gt; 'us-east-1',
          'version' =&gt; 'latest'
      ));
  } catch (S3Exception $e) {
      print_r($e-&gt;getMessage());
  }
  
  foreach($file['files']['tmp_name'] as $key =&gt; $tmp_name ){
      $file_name = $file['files']['name'][$key];
      $file_tmp = $file['files']['tmp_name'][$key];
  
      try { 
          $result = $s3Client-&gt;putObject(array(
              'Bucket'    =&gt; $awsCredentials['bucket'],
              'Key'       =&gt; "horsePhotos/".$horseId."/".$file_name,
              'SourceFile' =&gt; $file_tmp,
              'ACL'       =&gt; 'public-read'
          ));
      } catch(PDOException $e) {
          echo $e-&gt;getMessage();
      }
  }
  </code></pre>
  
  <p>For the life of me I can't figure out what I'm doing wrong. I can't seem to find any reference to this error when Googling.</p>
  
  <p>Any help would be great appreciated. Amazon's documentation is horrendously unhelpful.</p>
  
  <p>Thanks in advance.</p>