agentleFS
ai-enhanced-engineerai-enhanced-engineer/aiee-skills/skills/laravel-s3-storage/SKILL.md

laravel-s3-storage

Skill4 starsChanged 5 months agoMITView on GitHub

Laravel Flysystem S3 integration for file uploads. Storage facade usage, disk configuration, public/private file handling, signed URLs. Use for file upload features, video storage, image processing, or S3 integration.

The file

Files
SKILL.md

Laravel S3 Storage Patterns

Laravel's Flysystem S3 integration with support for public/private files and signed URLs.

When to Use

  • Implementing file upload features
  • Storing user-generated content (images, videos, documents)
  • Managing public vs private file access
  • Generating temporary download links
  • Streaming large files
  • Configuring S3 bucket security
  • Direct browser uploads to S3

Storage Facade Quick Reference

MethodPurposeExample
put()Upload fileStorage::disk('s3')->put('images', $file, 'public')
get()Download fileStorage::disk('s3')->get('file.jpg')
url()Get public URLStorage::disk('s3')->url($path)
temporaryUrl()Signed URL (private)Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(5))
delete()Delete fileStorage::disk('s3')->delete($path)
exists()Check existenceStorage::disk('s3')->exists($path)
putFileAs()Custom filenameStorage::disk('s3')->putFileAs('images', $file, 'custom.jpg')

Public vs Private Files

Public files are written with the 'public' ACL parameter and served via url(). Private files omit the visibility parameter (defaults to bucket policy) and are accessed via temporaryUrl() with a TTL — short TTLs (5 min) work well for authenticated downloads of short-lived links. See reference.md → Public vs Private Files for both upload + access flows.

File Validation Pattern

Pair $request->validate(['image' => 'required|image|mimes:jpeg,jpg,png|max:2048']) with the Storage::disk('s3')->put() call so MIME and size validation gate the upload. See reference.md → File Validation for the complete request/upload flow.

Document Upload Security Patterns

For uploaded-document use cases (KYC, legal docs), three security hardening patterns apply:

  • 'visibility' => 'private' on the disk config — defense-in-depth; even a misconfigured bucket ACL or CDN origin won't produce public URLs because Laravel writes with private ACL.
  • MIME-derived extension — build a server-side MIME_TO_EXT map keyed on the validated MIME type; never use getClientOriginalExtension() (attacker-controlled string).
  • Signed URL accessor with production re-throw — try { temporaryUrl() } catch (RuntimeException $e) { ... } pattern; re-throw in production to prevent silent fallback to a public URL on misconfigured S3-compatible disks (r2, do_spaces).

See reference.md → "Document Upload Security" for code skeletons.

Anti-Patterns

Anti-PatternPattern
403 ForbiddenCheck bucket policy and user permissions (incorrect IAM permissions)
CORS errorConfigure S3 bucket CORS (missing/incorrect CORS config)
File not visibleSet 'public' as third parameter in put() (wrong visibility setting)
Memory exhaustedUse fopen() streaming instead of file_get_contents() (loading large file into memory)
Slow uploadsUse multipart upload for files >100MB (single-threaded upload)
getClientOriginalExtension() in S3 key constructionAttacker-controlled extension in persisted key — derive from validated MIME via server-side map
=== 's3' driver-name branch for signed-URL fallbackAny S3-compatible driver with a different name (r2, do_spaces) silently falls through to public URL — use try/catch RuntimeException
Omitting 'visibility' => 'private' on S3 disk configSigned URL TTL is theatre if bucket policy regresses to public-read — set at config level for defense-in-depth

See reference.md for configuration, CORS setup, streaming patterns, security hardening, and IAM policies. See examples.md for complete upload actions, bucket policies, anti-patterns, and real-world implementations.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.