← Back to the sketchboard
notes from the desk

Laravel · AWS S3

Large uploads to S3 without choking your server

When an app takes big file uploads all day, streaming every file through PHP ties up workers and memory. A cleaner pattern: the browser uploads straight to S3 using a short-lived presigned URL that your Laravel app signs.

$client = Storage::disk('s3')->getClient();

$cmd = $client->getCommand('PutObject', [
    'Bucket' => config('filesystems.disks.s3.bucket'),
    'Key'    => 'uploads/' . Str::uuid() . '.pdf',
]);

$url = (string) $client
    ->createPresignedRequest($cmd, '+10 minutes')
    ->getUri();

Return $url to the front end, PUT the file to it, then save only the key in your database. Any heavy processing can run in a queued job, so the web request stays fast however large the file is.