
Delete file from amazon s3 bucket using Laravel
You can delete files from amazon s3 bucket using Laravel. You have to call the storage Facades with disk('s3’) and pass the object key or file path to delete method.
-
Delete a file from amazon s3 bucket using Laravel
//Syntax: Storage::disk('s3')->delete('path/file.jpg'); if(Storage::disk('s3')->exists($path)) { Storage::disk('s3')->delete($path); } //For example your path to file or object key will look like this. $path = 'uploaded_files/d486cebd-746c-4533-a53f-a0f8e77e15e2.jpg';
0It will delete the file from s3 bucket. File path is the key of an object (file) in amazon s3 bucket. You can get the key of the object after clicking on the object inside the folder. You can also store the key of the object in the table and delete the object (document) after passing the key to delete method dynamically.
To avoid exceptions you can check file exists or not in amazon s3 bucket using exists method.
Additional Info:
Use Storage facade
use Illuminate\Support\Facades\Storage;
Random Code Snippet Queries: Laravel
- Cannot end a section without first starting one
- Laravel specific table Migration
- Permanently delete a record in laravel
- Post model with title and body in laravel 8
- Touch parent updated_at in Laravel
- Create records using relationship in laravel
- Insert dummy data in users table Laravel
- How to get list of all views file in laravel
- Array to string conversion laravel blade
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to get CSRF token in laravel controller
- Delete records with relationship in laravel
- Redirect from www to non www in laravel using htaccess
- Class "App\Http\Controllers\Auth\Verified" not found
- Save or update pivot table data with additional column in Laravel
- How to restore multiple records after soft-deletes in Laravel
- How to use or operator in laravel
- Json encode method in laravel
- The use statement with non-compound name 'Auth' has no effect
- Laravel recursive function in controller
- How to return a column with different name in Laravel
- Get all users except the followings users in overtrue laravel-follow
- How to pass data to partial view file in laravel
- How to call controller function from view in Laravel
- How to pass data to route in laravel?