download s3 file laravel code example

Example 1: laravel download file from s3

$attachment = TicketAttachment::find($id);
$headers = [
    'Content-Type'        => 'application/jpeg',
    'Content-Disposition' => 'attachment; filename="'. $attachment->name .'"',
];
return \Response::make(Storage::disk('s3')->get($attachment->url), 200, $headers);

Example 2: laravel link storage to public

php artisan storage:link

Example 3: laravel s3 download file

return Storage::download('file.jpg');

return Storage::download('file.jpg', $name, $headers);

Example 4: download data from s3 and save to local disk laravel

$s3_file = Storage::disk('s3')->get(request()->file);
 $s3 = Storage::disk('public');
 $s3->put("./file_name.tif", $s3_file);

Tags:

Php Example