Skip to main content

Overview

The S3M class provides the core functionality for managing multipart uploads to AWS S3. It handles S3 client configuration, bucket management, and multipart upload completion. Namespace: MrEduar\S3M\S3M

Methods

getBucket()

Get the configured S3 bucket name from the configuration.
public static function getBucket(): string
return
string
The configured S3 bucket name from config('s3m.s3.bucket')

Example

use MrEduar\S3M\Facades\S3M;

$bucket = S3M::getBucket();
// Returns: 'my-s3-bucket'

ensureConfigureVariablesAreAvailable()

Validate that all required S3 configuration variables are available before performing operations.
public static function ensureConfigureVariablesAreAvailable(?array $options = []): void
options
array
Optional configuration overrides
options.bucket
string
Custom bucket name (if not provided, checks config)

Validated Configuration Keys

The method validates the following configuration keys from config('s3m.s3'):
  • bucket (unless provided in options)
  • region
  • key (AWS access key)
  • secret (AWS secret key)

Exceptions

InvalidArgumentException
\InvalidArgumentException
Thrown when required configuration variables are missing. The exception message includes the names of missing variables.

Example

use MrEduar\S3M\Facades\S3M;

try {
    S3M::ensureConfigureVariablesAreAvailable();
    // Configuration is valid, proceed with S3 operations
} catch (\InvalidArgumentException $e) {
    // Handle missing configuration
    // e.g., "Unable to issue signed URL. Missing S3M config variables: region, key"
}

// With custom bucket
S3M::ensureConfigureVariablesAreAvailable(['bucket' => 'custom-bucket']);

storageClient()

Create and return an AWS S3 client instance configured with the settings from your S3M configuration.
public function storageClient(): S3Client
return
\Aws\S3\S3Client
Configured AWS S3 client instance

Configuration

The client is configured using values from config('s3m.s3') with the following parameters:
  • region - AWS region
  • version - API version (always ‘latest’)
  • signature_version - Signature version (always ‘v4’)
  • use_path_style_endpoint - Path style endpoint setting
  • credentials - AWS credentials (key, secret, token)
  • url - Custom S3 endpoint URL (optional)
  • endpoint - Custom endpoint (optional)

Example

use MrEduar\S3M\Facades\S3M;

$client = S3M::storageClient();

// Use the client for custom S3 operations
$result = $client->listBuckets();

completeMultipartUpload()

Complete a multipart upload operation by assembling all uploaded parts into a single S3 object.
public function completeMultipartUpload(?array $options = []): array
options
array
Upload completion options
options.bucket
string
S3 bucket name (defaults to configured bucket)
options.key
string
required
The S3 object key (file path)
options.upload_id
string
required
The multipart upload ID from createMultipartUpload
options.parts
array
required
Array of uploaded parts with their ETags
options.parts[].PartNumber
integer
required
Part number (starting from 1)
options.parts[].ETag
string
required
ETag value returned from the part upload
return
array
AWS S3 response array containing upload details
Location
string
The URL of the uploaded object
Bucket
string
The bucket name
Key
string
The object key
ETag
string
The entity tag of the completed object

Example

use MrEduar\S3M\Facades\S3M;

$result = S3M::completeMultipartUpload([
    'bucket' => 'my-bucket',
    'key' => 'uploads/my-file.mp4',
    'upload_id' => 'example-upload-id-123',
    'parts' => [
        ['PartNumber' => 1, 'ETag' => '"etag-part-1"'],
        ['PartNumber' => 2, 'ETag' => '"etag-part-2"'],
        ['PartNumber' => 3, 'ETag' => '"etag-part-3"'],
    ]
]);

// Access the uploaded file URL
$fileUrl = $result['Location'];

Exceptions

InvalidArgumentException
\InvalidArgumentException
Thrown if required S3 configuration variables are missing

Facade Usage

All methods are available through the S3M facade:
use MrEduar\S3M\Facades\S3M;

// Get bucket
$bucket = S3M::getBucket();

// Validate configuration
S3M::ensureConfigureVariablesAreAvailable();

// Get S3 client
$client = S3M::storageClient();

// Complete upload
$result = S3M::completeMultipartUpload($options);

Build docs developers (and LLMs) love