Laravel 7 Download File from AWS S3 with Laravel Storage and delete it after

Before using the s3 driver, I did it like this

return response()->download(storage_path($path_to_file), $filename)->deleteFileAfterSend(true);

But now I don't know how to delete the file after downloading

return Storage::disk('s3')->get($path_to_file);

Upvotes: 1

Views: 1848

Answers (2)

Rabeea Ali
Rabeea Ali

Reputation: 146

You might download the file then delete it!

//download the file 
Storage::disk('s3')->get($file);
// delete it I prefer to make job for that 
Storage::disk('s3')->delete($file);

Upvotes: 2

Michael Mano
Michael Mano

Reputation: 3440

$file = Storage::disk('s3')->get($path_to_file);
Storage::disk('s3')->delete($path_to_file);

return $file;

Not sure if its possible to chain a delete, could give it a go.

Upvotes: 3

Related Questions