diff --git a/src/Http/Controllers/SignedStorageUrlController.php b/src/Http/Controllers/SignedStorageUrlController.php index 5143de7..0a3c7ad 100644 --- a/src/Http/Controllers/SignedStorageUrlController.php +++ b/src/Http/Controllers/SignedStorageUrlController.php @@ -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); } /**