-
-
Save anonymous/332d1c319aeeb70efd16fd51cb8b3a46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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