Decide what happens to an uploaded file once the controller has it: public under public/ or protected behind a controller, Flysystem so local development and S3 in production run the same code, a generated storage key with the original filename kept in the database, deletion that leaves no orphan file, and validation that actually inspects the bytes. Use this skill whenever someone asks to let users upload a document, add a profile picture or a book cover, attach a PDF or an invoice to a record, asks "where do the files go", wants to serve or download a stored file, wants only the owner to see a file, wants to add S3 or object storage or install Flysystem — and whenever a file is not found after deploying, an upload fails with an empty 422, files pile up after their record is deleted, or the URL of a private file turns out to be guessable.
Ships in Symfony Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Tier: on demand — applies the moment the application accepts a file. From then on, the public-versus-protected decision is core; Flysystem and object storage are the price of the suite's container deployment.
Where an uploaded file goes, how it comes back out, and what the database holds.
symfony-yoandev-http covers receiving the upload — #[MapUploadedFile], files inside a
payload DTO, the constraints that run at the boundary. This skill starts one line
later, at the point where a controller holds a valid UploadedFile and something has
to decide what to do with it.
public/ has no access control// Every authorisation rule in the project is now irrelevant for this file.
$file->move($this->getParameter('kernel.project_dir').'/public/uploads', $file->getClientOriginalName());
public/ is the web server's document root. FrankenPHP, nginx and Apache serve what
they find there without ever entering PHP, so access_control, #[IsGranted] and
every Voter in the project are bypassed — not defeated, simply never invoked. One line
walks around the whole security chapter.
Keeping the original filename makes it worse: /uploads/contrat-durand-2026.pdf is a
URL an attacker guesses rather than finds. And move() preserves whatever extension
the client sent, so evil.php lands in the document root of a machine configured to
execute PHP.
Two details verified in vendor/, because they change which precaution matters:
UploadedFile::move() does defend against path traversal.
File::getName() normalises \ to / and keeps only what follows the last slash,
so a client filename of ../../public/evil.php is written as evil.php. Traversal
is not the hole. The surviving extension is.League\Flysystem\PathTraversalDetected
for a key containing ../. So a storage key read back from the database cannot escape
its root either.| Public | Protected | |
|---|---|---|
| Examples | Book cover, avatar, public catalogue image | Invoice, contract, a reader's export, anything belonging to one user |
| Where | public/uploads/… in dev, an object-storage bucket with a CDN in production | Never under public/. A private bucket, or a directory outside the document root |
| Served by | The web server or the CDN, no PHP | A controller that checks authorisation, then streams the file |
| URL | Stable, may be cached publicly | Route with an id, or a short-lived signed URL |
Anything you cannot confidently put in the left column belongs in the right one. Moving a file from public to protected later means changing its URL everywhere and accepting that the old URL was already crawled; the reverse costs nothing.
symfony-yoandev-deployment ships Docker containers. A file written to a container's
filesystem is gone on the next deploy and invisible to every other replica — which
produces the symptom people report as "the file is not found after deploying" or "it
works, but only sometimes". A volume fixes the first half and not the second.
So: object storage (S3 or a compatible service) is the default for anything that must survive a deploy, and local disk is a development convenience. The way to have both without two code paths is Flysystem.
composer require league/flysystem-bundle # 3.7.x, pulls league/flysystem 3.x
composer require league/flysystem-async-aws-s3 async-aws/s3 # production adapter
composer require --dev league/flysystem-memory # in-memory adapter for tests
Verified: none of these are installed in the reference project — the recipe writes
config/packages/flysystem.yaml with a single local storage, which is a starting point
and not the final configuration. Configuration, autowiring and the traps:
references/storing-files.md.
Rejected: vich/uploader-bundle. It works, but it drives uploads from Doctrine
lifecycle events on the entity, which is exactly the behaviour-on-an-entity this
standard keeps out (see below). Also rejected: writing to %kernel.project_dir% by
hand — it is the same code as Flysystem's local adapter with none of the escape route
to S3.
The entity holds a storage key and the display metadata. Never the bytes, never an absolute path — an absolute path stops being true the moment the file moves to S3.
#[ORM\Column(length: 255, unique: true)]
private string $storageKey; // 2026/08/rapport-de-lecture-bbf84f80546c6e68.pdf
#[ORM\Column(length: 255)]
private string $originalName; // Rapport de lecture (final).pdf
#[ORM\Column(length: 100)]
private string $mimeType;
#[ORM\Column]
private int $sizeInBytes;
The original name is kept for display and for the Content-Disposition header. It is
never what is written to disk.
Deleting the entity does not delete the file. Something has to, and in this standard that something is the service:
flush() first, delete the file last. A file deleted before a flush() that
then fails leaves a row pointing at nothing, which is worse than an orphan file;flush() followed by a failed delete —
is swept by a scheduled command that compares stored keys against the database.A Doctrine lifecycle callback on the entity is not the answer here, even though it
is the obvious one. This standard's entities are maker-format data holders with no
behaviour, precisely so that every rule is in a service where it can be unit-tested and
where reading the service tells you the whole flow. A postRemove hook fires from
flush(), far from the code that asked for the deletion, and cannot be tested without
a database. The scheduled sweep is the safety net, not the mechanism.
Concrete code for both, plus the orphan-sweep query: references/storing-files.md.
The command's own mechanics (dry-run by default, locking) belong to symfony-yoandev-console;
scheduling it belongs to symfony-yoandev-async.
The extension and the Content-Type the browser sends are both attacker-controlled.
Measured on a PHP script renamed invoice.pdf and announced as application/pdf:
| Constraint | Result |
|---|---|
#[Assert\File(maxSize: '1M')] | accepted |
#[Assert\File(extensions: ['pdf'])] | rejected — The mime type of the file is invalid ("text/x-php") |
#[Assert\File(mimeTypes: ['application/pdf'])] | rejected — same sniffed type |
extensions: is the option to reach for: it checks the extension and derives the
matching media types from symfony/mime, then verifies the sniffed type against them.
UploadedFile::getMimeType() re-reads the file with finfo;
getClientMimeType() returns what the browser claimed, and returned
application/pdf for that script.
#[Assert\Image] accepts SVG by default. Verified: an SVG containing
<script>alert(1)</script> passes #[Assert\Image(maxWidth: 2000)], because Image
defaults mimeTypes to image/* when neither mimeTypes nor extensions is set, and
image/svg+xml matches that wildcard. Served inline from public/, that is stored XSS.
Write #[Assert\Image(extensions: ['jpg', 'png', 'webp'])] unless SVG is genuinely
wanted, and if it is, serve it as an attachment.
Two different limits with two very different failure modes, both measured:
| Situation | What PHP does | What the user sees |
|---|---|---|
Larger than upload_max_filesize | $_FILES entry present with error = UPLOAD_ERR_INI_SIZE, $_POST intact | A real validation message — Assert\File reports uploadIniSizeErrorMessage |
Larger than post_max_size | $_POST and $_FILES are both empty, only CONTENT_LENGTH survives | A bare 422 with no message, or "the CSRF token is invalid" |
The second one is the bug report that reads "the upload does nothing". A non-nullable
#[MapUploadedFile] argument with no file resolves to null, and the resolver throws
HttpException::fromStatusCode(422) with an empty message — nothing in the response
says a limit was hit. Set post_max_size above upload_max_filesize above the largest
maxSize in the application, and detect the case explicitly when it matters:
$request->headers->get('Content-Length') > 0 && !$request->request->count() && !$request->files->count().
| Symptom | Cause |
|---|---|
| File 404s after a deploy | Written to a container filesystem. Object storage, not a local directory |
| Works on one request, 404s on the next | Several replicas, local disk on each |
| A private file is reachable without logging in | It is under public/. No amount of access_control will change that |
| The upload "does nothing", empty 422 or a CSRF error | Body over post_max_size; the request arrived empty |
The file is too large but the file is small | maxSize is compared to a size PHP already truncated — check upload_max_filesize first |
A .php or .svg file was accepted | maxSize alone, or Assert\Image without extensions: |
| Files accumulate in the bucket | Nothing deletes them on entity removal, and no sweep exists |
A download returns the wrong Content-Type | BinaryFileResponse sniffs the content, not the stored MIME type — set the header |
| A protected download is cached by a proxy | new BinaryFileResponse(...) defaults to public: true |
#[MapUploadedFile], files in a payload DTO, the
version fallbacks: symfony-yoandev-http, references/input-mapping.md.intervention/image, liip/imagine-bundle) and a
decision about doing the work in a Messenger handler. Say so rather than improvising.symfony-yoandev-security. This skill only says
where to call it.--force, locking, smoke test:
symfony-yoandev-console. Scheduling it: symfony-yoandev-async.Flysystem is not a Symfony component and follows its own versions; the facts here were
checked against league/flysystem 3.35 and league/flysystem-bundle 3.7, installed
next to Symfony 8.1. #[IsSignatureValid] needs Symfony 7.4 and
Symfony\Component\HttpFoundation\UriSigner needs 6.4 — the fallbacks are in
references/serving-files.md. Everything else here (Assert\File, Assert\Image,
BinaryFileResponse, UploadedFile) is available across 6.4 → 8.x.
vendor/ is the source of truth over this file.
| File | When to read it |
|---|---|
references/storing-files.md | Configuring Flysystem, naming the stored file, what the entity holds, deleting without orphans, testing an upload without touching real storage |
references/serving-files.md | Getting the file back out: public URLs, a streaming controller, X-Sendfile / X-Accel-Redirect, signed URLs and S3 pre-signed URLs, cache headers |
What SKILL.md sets; muted values are Claude Code's defaults
/symfony-yoandev-skills:symfony-yoandev-storagefrom Symfony Skills
npx claudepluginhub yoanbernabeu/symfony-yoandev-skills --plugin symfony-yoandev-skills16 skills in this plugin
/symfony-yoandev-architectureDecide where code goes in a Symfony project and wire it correctly: the Controller / Service / Repository / DTO / Entity contract, the three DTO namespaces (Input, Read, Output), service design and who calls flush(), business exceptions carrying their own HTTP status, direct calls instead of domain events, configuration split between env vars, app. parameters and class constants, and the dependency-injection attributes (#[Autowire], #[AutowireIterator], #[AutowireLocator], #[AsDecorator], #[AsTaggedItem], #[Target], #[When], #[Lazy]). Use this skill whenever someone asks where a piece of logic belongs, wants a new service or DTO, says a controller has grown too big, wants to extract or move a class that has outgrown its place, asks how to make something configurable or add a setting or an env var, asks why a service is not autowired or how to inject one of several implementations, wants a factory, strategy, decorator or object mapping, or asks "is this the right place for this?", "how should I structure this feature?", "where does the rating logic go?", "extract this", "why does my exception return a 500?". Also use it for the list of alternatives this standard deliberately rejected and why. For a feature described in plain language, or a bare "refactor this" with no target, `symfony-yoandev-standards` routes first./symfony-yoandev-asyncMove work out of the request with Messenger, send email asynchronously with Mailer and TemplatedEmail, and run recurring jobs with Scheduler — Doctrine transport, retry and failure policy, prioritised queues, idempotent handlers, and workers under supervisor or systemd. Use this skill whenever someone asks to send an email, do something in the background, queue a job, run something every night or every five minutes, replace a crontab, speed up a slow import or a slow signup, process a big CSV, notify someone after an action, set up Messenger or a message handler or a worker, configure retries, deal with a message stuck in the failure queue, or says "my emails never arrive", "the import times out", "this page is slow because it sends mail", or "how do I schedule this"./symfony-yoandev-consoleWrite Symfony console commands as thin translation layers over a service: one class per command family with method-level #[AsCommand] on Symfony 8.1, invokable commands with #[Argument] and #[Option] before that, SymfonyStyle output, dry run by default with --force on anything destructive, mandatory locking on long or scheduled commands, clean shutdown on SIGTERM, and a smoke test with runCommand or CommandTester. Use this skill whenever someone asks to add a command, write a script, make something runnable from the terminal, build an import or an export or a batch job, clean up or purge or delete old data, backfill a column, send a digest, "run this once", "I need a CLI for this", "make:command", says a command times out or eats all the memory or deleted more than it should, or asks how to test a command. For scheduling that command to run every night, and for Messenger workers, use symfony-yoandev-async instead./symfony-yoandev-deploymentShip a Symfony application to production as a Docker image running FrankenPHP: the build and release sequence and what each step is for, migrations run automatically at deploy, production php.ini and OPcache preloading, environment variables and secrets on the server, Messenger workers under systemd or supervisor, post-deployment checks and rollback. Use this skill whenever someone says deploy this, put it in production, ship it, set up the server, prepare a Dockerfile or a production image, write a deploy script, run migrations on the server, restart the workers, configure OPcache or preloading, set environment variables in production, roll back a release — and equally when they describe a symptom: it works locally but not on the server, the site broke after deploying, my CSS is missing in production, production is slow, the workers are running old code, I get a 500 with no error message, the new code is not being picked up. Also use it before a first deployment, when nobody knows how the app is deployed./symfony-yoandev-doctrineThe persistence layer of a Symfony project: entities in maker format with attribute mapping, auto-increment integer ids, \DateTimeImmutable and native enums; relations and the collection traps they open; repositories as the single place where DQL, QueryBuilder and raw SQL are allowed; SELECT NEW projections into Read DTOs; who calls flush(); and migrations that are generated then read and corrected by hand. Use this skill whenever someone asks to create or change an entity, add a field or a column, store or persist something, link two things together, add a relation or a foreign key, write or fix a repository method, write a query, sort or filter a list from the database, count rows, make a query return less data, create or run a migration, rename a column without losing data, or asks "why is my query wrong", "why is this null", "why does saving not work", "the schema is out of sync", "I lost data after deploying"./symfony-yoandev-frontendBuild and debug the front end of a Symfony application with AssetMapper, Twig, Stimulus, Turbo and Symfony UX — no bundler, no Node build step. Use this skill whenever someone asks to make a page interactive, add a filter or a live search, add an autocomplete or a dropdown, add a JavaScript library, style a page or set up Tailwind, add an icon, build a reusable Twig component or a Live Component, add Turbo Drive, Frames or Streams, write a Stimulus controller, organise templates or translation keys, or set a form theme. Also use it for the failures: "my JavaScript does not run", "my JS stopped working after clicking a link", "the CSS did not update", "the page is slow to load", "the assets 404 in production", "the images are served by PHP", "importmap:audit is failing" — and whenever the question is *where* a piece of behaviour belongs, between a Stimulus controller, a Live Component and a Twig Component.Other plugins' skills for the same job