Get the FREE Ultimate OpenClaw Setup Guide →

laravel-filesystem-uploads

npx machina-cli add skill noartem/skills/laravel-filesystem-uploads-and-urls --openclaw
Files (1)
SKILL.md
803 B

Filesystem Uploads and URLs

Use the Storage facade consistently; abstract away the backend (local, S3, etc.).

Commands

$path = Storage::disk('public')->putFile('avatars', $request->file('avatar'));

// Temporary URLs (S3, etc.)
$url = Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(10));

// Streams
return Storage::disk('backups')->download('db.sql.gz');

Patterns

  • Keep user uploads under a dedicated disk with explicit visibility
  • Avoid assuming local paths; always go through Storage
  • For public assets, run storage:link and serve via web server / CDN
  • Validate mime/types and size limits at upload boundaries

Source

git clone https://github.com/noartem/skills/blob/main/skills/laravel-filesystem-uploads-and-urls/SKILL.mdView on GitHub

Overview

This skill teaches using the Laravel Storage facade to store user uploads on a configurable disk (local, S3, etc.), manage visibility, generate secure URLs, and stream files safely. It emphasizes abstracting the backend so code works across storage drivers and enforces validation at upload boundaries.

How This Skill Works

Uploads are handled through Storage::disk(...).putFile to save files to a chosen disk, then your code can generate temporary access via temporaryUrl for time-limited delivery or use download/stream methods to serve files. Always resolve paths via Storage instead of local paths, and keep visibility and credentials aligned with the disk configuration.

When to Use It

  • Storing user avatars or assets on a dedicated disk with explicit visibility (public or private).
  • Serving private files securely with temporary URLs (e.g., S3) for time-limited access.
  • Streaming large backups or datasets from a storage disk to users.
  • Serving public assets via a web server/CDN after running storage:link.
  • Maintaining backend-agnostic file handling across local, S3, and other disks using Storage.

Quick Start

  1. Step 1: Save an uploaded file to a chosen disk, e.g., Storage::disk('public')->putFile('avatars', $request->file('avatar'));
  2. Step 2: For private access, create a temporary URL: Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(10));
  3. Step 3: Stream or download with Storage::disk('backups')->download('db.sql.gz');

Best Practices

  • Use a dedicated disk for user uploads and set explicit visibility on putFile.
  • Always resolve file paths through Storage; avoid assuming local paths.
  • Validate MIME types and file size at the upload boundary.
  • Run php artisan storage:link for public assets and serve them through the web/CDN.
  • Use temporaryUrl for time-limited access and streaming safety.

Example Use Cases

  • Store user avatars on the public disk and serve them via a URL or CDN.
  • Generate a temporary URL on S3 for a user to download a private report.
  • Stream a large database backup from the backups disk to a user download.
  • Deliver publicly accessible assets after creating a storage:link and configuring a CDN.
  • Download a file directly from a non-public disk using Storage::disk(...)->download().

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers