Skip to main content

Overview

S3M provides several configuration options to control upload behavior, security, and storage settings. All options are defined in the config/s3m.php file.

Publishing Configuration

Publish the configuration file to customize S3M settings:
php artisan vendor:publish --provider="MrEduar\S3M\S3MServiceProvider"
This creates config/s3m.php in your project.

Configuration Options

Bucket Configuration

allow_change_bucket
boolean
default:"true"
Allows the client to specify a different S3 bucket for uploads.When enabled, users can upload to buckets other than the default configured bucket.
Enabling this option may have security implications. Ensure proper authorization checks are in place.
'allow_change_bucket' => true,

Visibility Configuration

allow_change_visibility
boolean
default:"true"
Allows the client to modify the visibility (ACL) of uploaded files.When enabled, users can set file visibility to public or private during upload.The default visibility is private if not specified.
'allow_change_visibility' => true,
Supported S3 visibility options include: private, public-read, public-read-write, authenticated-read, aws-exec-read, bucket-owner-read, bucket-owner-full-control.

Folder Configuration

allow_change_folder
boolean
default:"false"
Allows the client to specify a custom folder/directory for uploaded files.When disabled, all files are stored in the /tmp/ directory at the bucket root.The storage format is: /tmp/{filename} where {filename} is a UUID generated for each upload.
'allow_change_folder' => false,
Files in the /tmp/ directory should be automatically purged after 24 hours using an S3 lifecycle policy.

Middleware Configuration

middleware
array
default:"['web']"
Middleware stack applied to S3M routes.Define which middleware should be applied to the multipart upload endpoints.
'middleware' => [
    'web',
],
Always include authentication middleware to prevent unauthorized uploads.

S3 Connection Settings

s3
object
AWS S3 connection configuration.
's3' => [
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'token' => env('AWS_SESSION_TOKEN'),
    'region' => env('AWS_DEFAULT_REGION'),
    'bucket' => env('AWS_BUCKET'),
    'url' => env('AWS_URL'),
    'endpoint' => env('AWS_ENDPOINT'),
    'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],

S3 Parameters

s3.key
string
required
AWS Access Key ID from environment variable AWS_ACCESS_KEY_ID
s3.secret
string
required
AWS Secret Access Key from environment variable AWS_SECRET_ACCESS_KEY
s3.token
string
AWS Session Token for temporary credentials from environment variable AWS_SESSION_TOKEN
s3.region
string
required
AWS region (e.g., us-east-1, eu-west-1) from environment variable AWS_DEFAULT_REGION
s3.bucket
string
required
Default S3 bucket name from environment variable AWS_BUCKET
s3.url
string
Custom URL for accessing files (e.g., CloudFront CDN) from environment variable AWS_URL
s3.endpoint
string
Custom S3 endpoint for S3-compatible services from environment variable AWS_ENDPOINT
s3.use_path_style_endpoint
boolean
default:"false"
Use path-style endpoints instead of virtual-hosted-style from environment variable AWS_USE_PATH_STYLE_ENDPOINT

Complete Configuration Example

<?php

return [
    /**
     * Indicates whether the bucket of the uploaded file can be changed.
     * The default bucket is the one configured below.
     */
    'allow_change_bucket' => true,

    /**
     * Indicates whether the visibility of the uploaded file can be modified.
     * The default visibility setting is private.
     */
    'allow_change_visibility' => true,

    /**
     * Indicates whether the folder of the uploaded file can be changed.
     * By default, files are stored in the /tmp/ directory at the root of the bucket,
     * following the format /tmp/{filename}, where {filename} is the UUID generated for the upload.
     */
    'allow_change_folder' => false,

    /**
     * Middleware to be used for the multipart upload.
     */
    'middleware' => [
        'web',
    ],

    /**
     * S3 configuration.
     */
    's3' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'token' => env('AWS_SESSION_TOKEN'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => env('AWS_URL'),
        'endpoint' => env('AWS_ENDPOINT'),
        'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
    ],
];

Environment Variables

All AWS credentials should be stored in your .env file:
.env
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

# Optional
AWS_SESSION_TOKEN=your-session-token
AWS_URL=https://your-cdn.cloudfront.net
AWS_ENDPOINT=https://s3.custom-endpoint.com
AWS_USE_PATH_STYLE_ENDPOINT=false
Never commit your .env file to version control. Keep your AWS credentials secure.

Build docs developers (and LLMs) love