Menu

How to Upload Files to Amazon S3 in Laravel 13
📰

How to Upload Files to Amazon S3 in Laravel 13

DEV Community: aws·Muhammad Yasir Amin·3 days ago
#JSIHKjWO
#devtoaws#devto#dev#file#document
Reading 0:00
15s threshold

To upload files to Amazon S3 in Laravel 13, install league/flysystem-aws-s3-v3 , add your AWS credentials and bucket to .env , and store the uploaded file with $request->file('document')->store('documents', 's3') . Save the returned path in the database, and use Storage::disk('s3')->temporaryUrl() to give users time-limited access to private files.

Moving uploads off the web server is one of the first things I do when an app needs more than one server or a container-based deployment. Local disks do not survive redeploys and are not shared between instances; S3 solves both problems with almost no code change because Laravel's filesystem API stays the same.

Prerequisites

Laravel 13.x on PHP 8.3 or newer.

An AWS account, an S3 bucket, and an IAM user or role with permission to read and write that bucket.

Block Public Access left on for the bucket, unless you deliberately serve public files.

Step 1: Install the S3 driver

composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies

Enter…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.