---
title: "How to Upload Files to Amazon S3 Bucket in Laravel"
url: "https://magecomp.com/blog/upload-files-to-amazon-s3-bucket-laravel/"
date: "2026-01-23T13:07:52+00:00"
modified: "2026-01-23T13:07:53+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "Laravel"
word_count: 952
reading_time: "5 min read"
summary: "Amazon S3 (Simple Storage Service) is one of the most dependable and scalable cloud storage solutions. It is an excellent option for use when building a Laravel application that requires the abilit..."
description: "Learn how to upload files to an Amazon S3 bucket in Laravel with step-by-step configuration, code examples"
keywords: "Laravel"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Laravel 13: How to Use Query Scopes for Cleaner Queries"
    url: "https://magecomp.com/blog/laravel-13-use-query-scopes/"
  - title: "Mastering Authorization in Laravel: A Guide to Gates and Policies"
    url: "https://magecomp.com/blog/laravel-gates-policies/"
  - title: "How to Get Customer Segments Using GraphQL API in Shopify Remix App"
    url: "https://magecomp.com/blog/get-customer-segments-using-graphql-api-shopify-remix-app/"
---

# How to Upload Files to Amazon S3 Bucket in Laravel

_Published: January 23, 2026_  
_Author: Bharat Desai_  

![How to Upload Files to Amazon S3 Bucket in Laravel](https://magecomp.com/blog/wp-content/uploads/2026/01/How-to-Upload-Files-to-Amazon-S3-Bucket-in-Laravel-1024x512.webp)

Amazon S3 (Simple Storage Service) is one of the most dependable and scalable cloud storage solutions. It is an excellent option for use when building a Laravel application that requires the ability to upload files (such as images, documents or backups).

[![Hire laravel Developer](https://magecomp.com/blog/wp-content/uploads/2024/12/Hire-Laravel-Expert-Now-3-1024x284.webp)](https://magecomp.com/services/hire-laravel-developer/)When we create web applications today, it is common to have the need to allow users to upload files; using local “storage” to save the uploaded files works fine for small projects, but it quickly becomes insufficient as the application grows. Saving files locally will take up an incredible amount of server disk space and make it much more difficult to load balance.

In the following tutorial, you will see the step by step process to upload files from your Laravel application to a bucket in Amazon S3.

## Prerequisites
You will need to have the following before starting this tutorial:

- A running Laravel installation.
- An active AWS Account.
- An S3 Bucket created in your AWS console.
- AWS Access Keys (Access Key ID and Secret Access Key) for an IAM user with S3 permissions.

## Steps to Upload Files to Amazon S3 Bucket in Laravel:
### Step 1: Install S3 Driver
By default, Laravel creates a composer.json file with the necessary dependencies. However, to use the S3 driver, we need to install the Flysystem S3 package.

Open your terminal and run the following command:

```
composer require league/flysystem-aws-s3-v3 "^3.0"
```

This package allows Laravel’s filesystem to communicate with Amazon S3.

### Step 2: Configure Environment Variables
After you have installed the package, you will want to set your AWS credentials. In the .env file located in your project’s root, find the following keys and replace them with your own credentials for AWS S3.

```
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your-bucket-name
AWS_USE_PATH_STYLE_ENDPOINT=false
```

**Note:** Make sure to replace your-access-key-id, your-secret-access-key, us-east-1, and your-bucket-name with your actual AWS credentials.

### Step 3: Create Controller for File Upload
Next, we will make a controller that will contain the logic for uploading files to S3. You can do this by executing the following command:

```
php artisan make:controller S3UploadController
```

Open the newly created file at app/Http/Controllers/S3UploadController.php and add the following code:

```
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateSupportFacadesStorage;
class S3UploadController extends Controller
{
    public function uploadForm()
    {
        return view('s3-upload');
    }
    public function uploadFile(Request $request)
    {
        // Validate the file
        $request->validate([
            'file' => 'required|mimes:jpg,png,pdf,csv|max:2048',
        ]);
        if ($request->hasFile('file')) {
            $file = $request->file('file');
            // Upload file to S3
            $path = Storage::disk('s3')->put('uploads', $file);
            // Get the file URL
            $url = Storage::disk('s3')->url($path);
            return back()->with('success', 'File uploaded successfully to S3!')->with('url', $url);

        }
        return back()->with('error', 'Error uploading file.');
    }
}
```

**Explanation:**

- We use Storage::disk(‘s3’)->put() to upload the file to the “uploads” folder inside your S3 bucket.
- The url() method retrieves the public URL of the uploaded file (ensure your bucket policy allows public access if you need to display it).

### Step 4: Create Routes
Next, we need to define the routes to display the upload form and handle the POST request. Open routes/web.php and add:

```
use AppHttpControllersS3UploadController;
Route::get('s3-upload', [S3UploadController::class, 'uploadForm']);
Route::post('s3-upload', [S3UploadController::class, 'uploadFile'])->name('s3.upload');
```

### Step 5: Create the Blade View
Finally, create a simple Blade file to display the upload form. Create a new file resources/views/s3-upload.blade.php and add the following code:

```

<html>
<head>
    <title>Laravel S3 File Upload Example - MageComp</title>
    </head>
<body>
            <h2 class="text-center mb-4">Upload File to Amazon S3 in Laravel</h2>
        @if(session('success'))
                            {{ session('success') }} <br>
                <strong>File URL:</strong> <a href="{{ session(&#039;url&#039;) }}" target="_blank" data-wpel-link="internal" rel="follow">View File</a>
                    @endif
                    <form action="{{ route('s3.upload') }}" method="POST" enctype="multipart/form-data">
                @csrf
                                    <label class="form-label">Choose File:</label>
                    <input type="file" name="file" class="form-control" required>
                                <button type="submit" class="btn btn-primary">Upload to S3</button>
            </form>
            </body>
</html>
```

## Conclusion
That’s it! You have successfully integrated Amazon S3 with your Laravel application.

Using S3 ensures that your application remains lightweight and your files are stored securely on the cloud. You can now easily handle large file uploads without worrying about local server storage limits.

[![Laravel Development Services](https://magecomp.com/blog/wp-content/uploads/2024/12/Laravel-Development-Services-4-1024x284.webp)](https://magecomp.com/services/laravel-development-services/)

## FAQ
**1. Is Amazon S3 free to use?**

Amazon S3 is not completely free. AWS provides a free tier with limited storage, but charges apply based on usage, storage size, and data transfer.

**2. Can I upload multiple files to S3 in Laravel?**

Yes. You can loop through multiple files and upload them using the same Storage::disk(‘s3’) method.

**3. Can I use S3 for large file uploads?**

Yes! AWS S3 provides a way for you to upload very large files as well as being a great option to use for large audio/video files due to its multipart upload functionality.

**4. What is the maximum file size I can upload?**

When you upload a single file, the maximum size allowed is 5GB. If you need to upload larger files to AWS S3, then AWS S3 has a multipart upload feature that allows you to break down the file into several smaller parts up to 5 terabytes.

</body></html>


---

_View the original post at: [https://magecomp.com/blog/upload-files-to-amazon-s3-bucket-laravel/](https://magecomp.com/blog/upload-files-to-amazon-s3-bucket-laravel/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-22 23:48:36 UTC_  
