Skip to content

Commit

Permalink
Merge pull request #17 from PrestigeT/feature
Browse files Browse the repository at this point in the history
Add Amazon S3 Transfer Acceleration option
  • Loading branch information
eddturtle committed Oct 31, 2017
2 parents 72efb67 + f8340a4 commit f23ef99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -88,6 +88,7 @@ Options can be passed into the Signature class as a fifth parameter, below is a
| content_type | | Strictly only allow a single content type, blank will allow all. Will fail with a AccessDenied 403 is this condition is not met. |
| encryption | false | Sets whether AWS server side encryption should be applied to the uploaded files, so that files will be encrypted with AES256 when at rest. |
| custom_url | null | Allow S3 compatible solutions by specifying the domain it should POST to. Must be a valid url (inc. http/https) otherwise will throw InvalidOptionException. |
| accelerate | false | Set Amazon S3 Transfer Acceleration |
| additional_inputs | | Any additional inputs to add to the form. This is an array of name => value pairs e.g. ['Content-Disposition' => 'attachment'] |

For example:
Expand Down
8 changes: 7 additions & 1 deletion src/Signature.php
Expand Up @@ -60,6 +60,9 @@ class Signature
// a valid url (inc. http/https) otherwise will throw InvalidOptionException.
'custom_url' => null,

// Set Amazon S3 Transfer Acceleration
'accelerate' => false,

// Any additional inputs to add to the form. This is an array of name => value
// pairs e.g. ['Content-Disposition' => 'attachment']
'additional_inputs' => []
Expand Down Expand Up @@ -174,7 +177,10 @@ private function buildAmazonUrl()
$middle = "";
}

return "//" . self::SERVICE . $middle . ".amazonaws.com" . "/" . urlencode($this->bucket);
if($this->options['accelerate'])
return "//" . urlencode($this->bucket) . "." . self::SERVICE . "-accelerate.amazonaws.com";
else
return "//" . self::SERVICE . $middle . ".amazonaws.com" . "/" . urlencode($this->bucket);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/SignatureTest.php
Expand Up @@ -95,7 +95,7 @@ public function testGetOptions()
{
$object = new Signature('key', 'secret', 'test', $this->testRegion);
$options = $object->getOptions();
$this->assertTrue(count($options) === 10);
$this->assertTrue(count($options) === 11);
$this->assertArrayHasKey('success_status', $options);
$this->assertArrayHasKey('acl', $options);
$this->assertArrayHasKey('default_filename', $options);
Expand Down

0 comments on commit f23ef99

Please sign in to comment.