config/s3m.php file. This reference documents all available configuration options.
Configuration File
The configuration file is published to your Laravel application atconfig/s3m.php when you run:
Upload Behavior
allow_change_bucket
Controls whether clients can specify a custom S3 bucket when creating uploads.
- When
true: Clients can pass abucketparameter to override the default bucket - When
false: All uploads use the default bucket configured ins3.bucket
false in production if you want to restrict uploads to a single bucket.config/s3m.php
allow_change_visibility
Controls whether clients can specify custom ACL visibility (public/private) for uploads.
- When
true: Clients can pass avisibilityparameter (e.g.,public-read,private) - When
false: All uploads use the default visibility ofprivate
private (see S3MultipartController.php:166)config/s3m.php
allow_change_folder
Controls whether clients can specify a custom folder/prefix for S3 object keys.
- When
true: Clients can pass afolderparameter to customize the upload path - When
false: All uploads are stored in the/tmp/directory
/tmp/{uuid} where {uuid} is auto-generatedCustom Path Example: When enabled, client can specify folder: "uploads/documents" to store at /uploads/documents/{uuid}config/s3m.php
Disabling
allow_change_folder is recommended for security to prevent path traversal attacks and ensure consistent file organization.Middleware
middleware
Array of middleware to apply to all S3M routes (multipart creation, signing, completion).Common Middleware:
web: Session, CSRF protection, cookiesauth: Require authenticated usersauth:sanctum: API token authentication- Custom middleware for rate limiting, logging, etc.
Middleware is applied in the controller constructor (see S3MultipartController.php:24)
S3 Credentials
s3
AWS S3 connection configuration. All credentials are read from environment variables by default.
s3.key
AWS Access Key ID for S3 authentication.Environment Variable:
AWS_ACCESS_KEY_IDs3.secret
AWS Secret Access Key for S3 authentication.Environment Variable:
AWS_SECRET_ACCESS_KEYs3.token
AWS Session Token for temporary credentials (optional).Environment Variable:
AWS_SESSION_TOKENUse Case: Required when using IAM role temporary credentials or STS assumed roles.s3.region
AWS region where your S3 bucket is located.Environment Variable:
AWS_DEFAULT_REGIONExamples: us-east-1, eu-west-1, ap-southeast-1s3.bucket
Default S3 bucket name for uploads.Environment Variable:
AWS_BUCKETNote: Can be overridden per-upload if allow_change_bucket is true.s3.url
Custom S3 URL for accessing uploaded files (optional).Environment Variable:
AWS_URLUse Case: CloudFront distribution URL or custom domain for S3 assets.s3.endpoint
Custom S3 endpoint URL (optional).Environment Variable:
AWS_ENDPOINTUse Case: S3-compatible services like MinIO, DigitalOcean Spaces, Wasabi, etc.Example: https://nyc3.digitaloceanspaces.coms3.use_path_style_endpoint
Use path-style S3 URLs instead of virtual-hosted-style.Environment Variable:
AWS_USE_PATH_STYLE_ENDPOINTfalse: Virtual-hosted style (default):https://bucket-name.s3.region.amazonaws.com/keytrue: Path style:https://s3.region.amazonaws.com/bucket-name/key
Complete Configuration Example
Security Best Practices
Production Configuration
Production Configuration
Recommended production settings:This prevents clients from manipulating upload destinations and requires authentication.
IAM Permissions
IAM Permissions
Ensure your AWS IAM user/role has these S3 permissions:
s3:PutObjects3:GetObject(for presigned URLs)s3:CreateMultipartUploads3:UploadParts3:CompleteMultipartUploads3:AbortMultipartUpload
Environment Variables
Environment Variables
Never commit AWS credentials to version control. Always use environment variables and ensure
.env is in .gitignore.CORS Configuration
CORS Configuration
If uploading from browser, configure S3 bucket CORS to allow PUT requests from your domain: