Skip to content

Commit

Permalink
Merge pull request #6 from TappNetwork/upgrade_to_uppy_v2
Browse files Browse the repository at this point in the history
Upgrade to Uppy v2 to pre-sign URLs in batches
  • Loading branch information
andreia authored Sep 20, 2021
2 parents 23f23fe + 14b2937 commit d124b29
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 17 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,31 @@ All notable changes to `laravel-uppy-s3-multipart-upload` will be documented in

- Add S3 transfer acceleration configuration
- Update README

## 0.3.1 - 2021-02-27

- Move S3 transfer acceleration config to the package config file

## 0.3.2 - 2021-02-28

- Update the way credentials are passed to use the Credentials class

## 0.3.3 - 2021-03-03

- Remove passing credentials, assuming that AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set in the .env based on the AWS SDK suggestions

## 0.3.4 - 2021-03-18

- Use Flysystem AWS client

## 0.3.5 - 2021-09-15

- Add support for multiple Uppy instances
- Update README

## 0.4 - 2021-09-20

- Upgrade Uppy from 1.x to 2.0
- Add support for pre-sign URLs in batches
- Update README
- Add upgrade guide
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ Add on your `package.json` file the Uppy JS libraries and AlpineJS library:
...
},
"dependencies": {
"@uppy/aws-s3-multipart": "^1.8.12",
"@uppy/core": "^1.16.0",
"@uppy/drag-drop": "^1.4.24",
"@uppy/status-bar": "^1.9.0",
"@uppy/aws-s3-multipart": "^2.0.2",
"@uppy/core": "^2.0.2",
"@uppy/drag-drop": "^2.0.1",
"@uppy/status-bar": "^2.0.1"
...
}
...
Expand Down
31 changes: 31 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Upgrade Guide

## Upgrading from 0.3.5 to 0.4.0

### To upgrade Uppy from 1.x to 2.0

Update the following dependencies on your `package.json`:

```json
"dependencies": {
...
"@uppy/aws-s3-multipart": "^2.0.2",
"@uppy/core": "^2.0.2",
"@uppy/drag-drop": "^2.0.1",
"@uppy/status-bar": "^2.0.1"
}
```

Install the dependencies and compile assets:

```bash
npm install
npm run dev
```

Clear caches:

```bash
php artisan optimize
php artisan view:clear
```
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Route::get('/s3/multipart/{uploadId}', [UppyS3MultipartController::class, 'getUploadedParts']);

Route::get('/s3/multipart/{uploadId}/{partNumber}', [UppyS3MultipartController::class, 'prepareUploadPart']);
Route::get('/s3/multipart/{uploadId}/batch', [UppyS3MultipartController::class, 'prepareUploadParts']);

Route::post('/s3/multipart/{uploadId}/complete', [UppyS3MultipartController::class, 'completeMultipartUpload']);

Expand Down
28 changes: 16 additions & 12 deletions src/Http/Controllers/UppyS3MultipartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,32 @@ private function listPartsPage($key, $uploadId, $partIndex, $parts = null)
https://github.com/transloadit/uppy/blob/master/packages/%40uppy/aws-s3-multipart/src/index.js#L104
return this.client.get(`s3/multipart/${uploadId}/${number}?key=${filename}`)
return this.client.get(`s3/multipart/${uploadId}/batch?key=${filename}&partNumbers=${partNumbers.join(',')}`)
.then(assertServerError)
*/
public function prepareUploadPart(Request $request, $uploadId, $partNumber)
public function prepareUploadParts(Request $request, $uploadId)
{
$key = $this->encodeURIComponent($request->input('key'));

$command = $this->client->getCommand('uploadPart', [
'Bucket' => $this->bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'Body' => '',
]);
$partNumbers = explode(',', $request->input('partNumbers'));

$presignedUrls = [];

$presignedRequest = $this->client->createPresignedRequest($command, config('uppy-s3-multipart-upload.s3.presigned_url.expiry_time'));
foreach ($partNumbers as $partNumber) {
$command = $this->client->getCommand('uploadPart', [
'Bucket' => $this->bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => (int) $partNumber,
'Body' => '',
]);

$presignedUrl = (string) $presignedRequest->getUri();
$presignedUrls[$partNumber] = (string) $this->client->createPresignedRequest($command, config('uppy-s3-multipart-upload.s3.presigned_url.expiry_time'))->getUri();
}

return response()
->json([
'url' => $presignedUrl,
'presignedUrls' => $presignedUrls,
]);
}

Expand Down

0 comments on commit d124b29

Please sign in to comment.