Skip to content

Instantly share code, notes, and snippets.

/web.php Secret

Created January 18, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/332d1c319aeeb70efd16fd51cb8b3a46 to your computer and use it in GitHub Desktop.
Save anonymous/332d1c319aeeb70efd16fd51cb8b3a46 to your computer and use it in GitHub Desktop.
<?php
Route::get('/download/{fullPath}/{attachment}', function($fullPath, $attachment) {
try {
$s3Client = Storage::cloud()->getAdapter()->getClient();
$stream = $s3Client->getObject([
'Bucket' => env('AWS_BUCKET'),
'Key' => $fullPath
]);
return response($stream['Body'], 200)->withHeaders([
'Content-Type' => $stream['ContentType'],
'Content-Length' => $stream['ContentLength'],
'Content-Disposition' => 'inline; filename="' . $attachment . '"'
]);
} catch (S3Exception $e) {
abort( 401, 'The requested file not exists');
} catch (AwsException $e) {
abort( 401, 'An error as ocurred');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment