Skip to content

Commit 4171c36

Browse files
committed
Add S3 transfer acceleration config
1 parent 52ea09e commit 4171c36

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ All notable changes to `laravel-uppy-s3-multipart-upload` will be documented in
1212
- Fix variable name
1313
- Allow CSRF
1414
- Update README
15+
16+
## 0.3 - 2021-02-26
17+
18+
- Add S3 transfer acceleration configuration
19+
- Update README

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ return [
108108

109109
### AWS S3 Setup
110110

111-
This package installs the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) and use Laravel's default `s3` disk configuration from `filesystems.php` file.
111+
This package installs the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) and use Laravel's default `s3` disk configuration from `config/filesystems.php` file.
112112

113113
You just have to add your S3 keys, region, and bucket using the following env vars in your `.env` file:
114114

@@ -171,6 +171,23 @@ https://uppy.io/docs/aws-s3-multipart/#S3-Bucket-Configuration
171171

172172
https://uppy.io/docs/aws-s3/#S3-Bucket-configuration
173173

174+
#### Add S3 Transfer Acceleration
175+
176+
To use [S3 transfer acceleration](https://docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration.html), enable it adding a `'use_accelerate_endpoint' => env('AWS_USE_ACCELERATE_ENDPOINT')` option on `s3` key in `config/filesystems.php` file:
177+
178+
```php
179+
's3' => [
180+
...
181+
'use_accelerate_endpoint' => env('AWS_USE_ACCELERATE_ENDPOINT'),
182+
],
183+
```
184+
185+
Add on your `.env` file this env var:
186+
187+
```
188+
AWS_USE_ACCELERATE_ENDPOINT=true
189+
```
190+
174191
#### Configuration
175192

176193
You can configure the folder to upload the files and the expiration of the presigned URLs used to upload the parts, with the `config/uppy-s3-multipart-upload.php` file:
@@ -372,7 +389,7 @@ Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
372389

373390
## Security Vulnerabilities
374391

375-
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
392+
If you discover any security-related issues, please email security@tappnetwork.com.
376393

377394
## Credits
378395

src/Http/Controllers/UppyS3MultipartController.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Http\Request;
77
use Illuminate\Http\Response;
88
use Illuminate\Support\Str;
9+
use Throwable;
910

1011
class UppyS3MultipartController extends Controller
1112
{
@@ -17,8 +18,8 @@ public function __construct()
1718
{
1819
$this->client = new S3Client([
1920
'version' => 'latest',
20-
'region' => config('filesystems.disks.s3.region'),
21-
'use_accelerate_endpoint' => false,
21+
'region' => config('filesystems.disks.s3.region'),
22+
'use_accelerate_endpoint' => config('filesystems.disks.s3.use_accelerate_endpoint'),
2223
'credentials' => [
2324
'key' => config('filesystems.disks.s3.key'),
2425
'secret' => config('filesystems.disks.s3.secret'),
@@ -106,12 +107,19 @@ public function createMultipartUpload(Request $request)
106107
$folder = config('uppy-s3-multipart-upload.s3.bucket.folder') ? config('uppy-s3-multipart-upload.s3.bucket.folder').'/' : '';
107108
$key = $folder.Str::of($fileName.'_'.microtime())->slug('_').'.'.$fileExtension;
108109

109-
$result = $this->client->createMultipartUpload([
110-
'Bucket' => $this->bucket,
111-
'Key' => $key,
112-
'ContentType' => $type,
113-
'ContentDisposition' => 'inline',
114-
]);
110+
try {
111+
$result = $this->client->createMultipartUpload([
112+
'Bucket' => $this->bucket,
113+
'Key' => $key,
114+
'ContentType' => $type,
115+
'ContentDisposition' => 'inline',
116+
]);
117+
} catch (Throwable $exception) {
118+
return response()
119+
->json([
120+
'message' => $exception->getMessage(),
121+
], $exception->getStatusCode());
122+
}
115123

116124
return response()
117125
->json([

0 commit comments

Comments
 (0)