Skip to content

Commit

Permalink
Add Custom key to s3 signed storage (#120)
Browse files Browse the repository at this point in the history
* add custom key to s3 signed storage

* fix ci

* formatting

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
luanfreitasdev and taylorotwell authored Feb 3, 2022
1 parent ed5f3d6 commit c558f64
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Http/Controllers/SignedStorageUrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,29 @@ public function store(Request $request)

$uuid = (string) Str::uuid();

$key = $request->input('key') ?: 'tmp/'.$uuid;

$expiresAfter = config('vapor.signed_storage_url_expires_after', 5);

$signedRequest = $client->createPresignedRequest(
$this->createCommand($request, $client, $bucket, $key = ('tmp/'.$uuid)),
$this->createCommand($request, $client, $bucket, $key),
sprintf('+%s minutes', $expiresAfter)
);

$uri = $signedRequest->getUri();

return response()->json([
'uuid' => $uuid,
$response = [
'bucket' => $bucket,
'key' => $key,
'url' => $uri->getScheme().'://'.$uri->getAuthority().$uri->getPath().'?'.$uri->getQuery(),
'headers' => $this->headers($request, $signedRequest),
], 201);
];

if (! $request->has('key')) {
$response['uuid'] = $uuid;
}

return response()->json($response, 201);
}

/**
Expand Down

0 comments on commit c558f64

Please sign in to comment.