Skip to content

Instantly share code, notes, and snippets.

/web.php Secret

Created Jan 18, 2018
Embed
What would you like to do?
<?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
You can’t perform that action at this time.