/symfony-ux-skills:ux-uploadfrom symfony-ux-skills
Replaces Symfony FileType with UploadType for background file uploads with drag-and-drop, image previews, progress bars, chunking, pause/resume, and uploads that survive form validation errors.
Ships in symfony-ux-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.
Upload files in the background before a Symfony Form is submitted. Users select, drop or paste files, follow progress, pause and resume, and fix other fields' validation errors while their files stay uploaded. UploadType replaces FileType and returns an UploadedFile that extends HttpFoundation's, so move() keeps working.
Since Symfony UX 3.8+. The package is experimental: its API may still change.
composer require symfony/ux-upload
Until a Flex recipe exists, register the bundle and the routes yourself:
// config/bundles.php
Symfony\UX\Upload\UXUploadBundle::class => ['all' => true],
# config/routes/ux_upload.yaml
ux_upload:
resource: '@UXUploadBundle/config/routes.php'
prefix: /_ux/upload
trailing_slash_on_root: false
Requires StimulusBundle. Assets: php bin/console importmap:install (AssetMapper) or npm install && npm run dev (Encore, Reprise). The stylesheet is opt-in (see Styling). Schedule cleanup from day one:
*/15 * * * * cd /path/to/app && php bin/console ux:upload:cleanup --age=24h
Every upload needs an identity. With SecurityBundle the logged-in user is used; an anonymous visitor needs more than a firewall to be identified. For public forms, add a session-based resolver (see Security below).
If several application nodes handle uploads, read the distributed deployment configuration for shared storage and locking.
# config/packages/ux_upload.yaml
ux_upload:
uploaders:
documents:
max_size: 50M
allowed_types: [application/pdf]
use Symfony\UX\Upload\Form\UploadType;
$builder
->add('document', UploadType::class, [
'uploader' => 'documents',
'constraints' => [new NotBlank()],
])
->add('title', TextType::class, ['constraints' => [new NotBlank()]]);
use Symfony\UX\Upload\Upload\UploadedFile;
if ($form->isSubmitted() && $form->isValid()) {
/** @var UploadedFile|null $upload */
$upload = $form->get('document')->getData();
if (null !== $upload) {
$upload->move($directory, $upload->getId().'.'.($upload->guessExtension() ?? 'bin'));
}
return $this->redirectToRoute('document_new');
}
Render with form_row(form.document) as usual. Name the final file from getId(): repeated submissions hit the same target, and client filenames stay out of the way.
| Option | Default | Notes |
|---|---|---|
uploader | default | Named server policy |
max_size | null | Inherits the uploader; may only narrow it |
allowed_types | [] | MIME list; may only narrow the uploader |
multiple | false | Returns list<UploadedFile> |
max_files | null | Count limit with multiple |
layout | compact | compact or dropzone |
show_preview | false | Image previews |
auto_upload | true | Start right after selection |
compression | false | gzip bodies and chunks (also needs the uploader) |
widget_attr | [] | Attributes on the widget container (attr goes to the native input) |
help_text, invalid_message | generated |
Required and mapped by default, like FileType; pass required: false for an optional file.
For dropzones, previews and client-side presentation, see customizing the upload field. To react to progress, completion or validation errors in Stimulus, see the browser events reference.
ux_upload:
max_size: 100M # global limit, 0 disables it
uploaders:
avatars:
max_size: 5M
allowed_types: [image/jpeg, image/png, image/webp]
chunk_size: 1M
completed_ttl: 3600
documents:
max_size: 100M
allowed_types: [application/pdf]
The uploader name is signed into the policy and the token: a token from another uploader is rejected. Overridable per uploader: max_size, allowed_types, chunk_size, parallel_chunks, compression, integrity_algorithm, completed_ttl, max_pending_per_owner.
UploadedFile is a temporary reference. Copy it into your own storage, then record the final location:
$stream = $upload->openStream(); // no local copy, works with Flysystem
try {
$attachment = $this->storage->storeOnce($upload->getId(), $stream, $upload->getClientOriginalName());
} finally {
fclose($stream);
}
getId() (double click, proxy retry). Under concurrency, enforce it with a unique constraint rather than a lookup before the write.delete() in the same request: a second valid submission may still need the stream. Let ux:upload:cleanup remove it after completed_ttl.getStoragePath(); cleanup deletes that path.getClientOriginalName(), getMimeType(), getSize(), getChecksum()...) never touch the file: they read signed data. getPathname(), getContent(), the File/Image constraints and the dev profiler copy the whole file locally first.use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\UX\Upload\Security\UploadContext;
use Symfony\UX\Upload\Security\UploadContextResolverInterface;
final class SessionUploadContextResolver implements UploadContextResolverInterface
{
public function __construct(private readonly RequestStack $requestStack) {}
public function resolve(): UploadContext
{
$request = $this->requestStack->getMainRequest();
if (null === $request || !$request->hasSession()) {
return new UploadContext();
}
$session = $request->getSession();
$owner = $session->get('upload_owner');
if (!\is_string($owner) || '' === $owner) {
$owner = bin2hex(random_bytes(16));
$session->set('upload_owner', $owner);
}
return new UploadContext(ownerId: $owner);
}
}
# config/services.yaml
services:
Symfony\UX\Upload\Security\UploadContextResolverInterface:
alias: App\Upload\SessionUploadContextResolver
Tokens are bound to owner, tenant, form field and uploader, and signed with kernel.secret. allow_anonymous: true shares one context (and one quota) between all visitors: only with a rate_limiter. CSRF is checked automatically when symfony/security-csrf is installed.
use Symfony\UX\Upload\LiveComponent\Attribute\UploadTarget;
use Symfony\UX\Upload\LiveComponent\ComponentWithUploadTrait;
#[AsLiveComponent]
final class ProfilePhoto
{
use ComponentWithUploadTrait;
use DefaultActionTrait;
#[LiveProp]
#[UploadTarget(uploader: 'avatars')]
public ?string $photo = null; // nullable string: holds the signed token
public function getPhotoUpload(): ?UploadedFile
{
return $this->getUpload('photo');
}
}
<div{{ attributes.defaults(stimulus_controller('symfony/ux-upload/live-upload', {property: 'photo'})) }}>
{{ form_row(this.uploadForm.photo) }} {# an UploadType built with 'data' => this.photoUpload #}
</div>
The bridge calls the applyUpload action on upload completion; clearUpload deletes the temporary file and nulls the property. Keep the field out of data-live-ignore.
Opt in to the stylesheet in assets/controllers.json ("@symfony/ux-upload/dist/style.min.css": true under the upload controller's autoimport), then theme with --ux-upload-accent, --ux-upload-bg, --ux-upload-border, --ux-upload-radius... Without it, the native file input stays visible and usable, and your form theme rules. To change markup, {% use '@UXUpload/form_theme.html.twig' %} in your own form theme and override blocks (ux_upload_actions, ux_upload_item...) keeping the data-ux-upload-* hooks.
Configure policy on named uploaders; fields only narrow it.
Identify every visitor. Logged-in user, a session resolver, or a deliberate allow_anonymous with rate limiting.
Temporary is temporary. Copy with openStream() or move(), persist idempotently, let cleanup delete.
Fit chunk_size to PHP and proxy limits. Files up to chunk_size go in one multipart POST; larger files go in chunks.
symfony/ux-upload on Packagist.UploadedFile API, server and DOM events, JavaScript Uploader, form theme blocks, storage backends, testing): references/reference.mdEach demo shows the code behind the example. Upload demo catalog
The package page also embeds a PDF form that keeps its file after validation errors and a photo grid with image previews.
ComponentWithUploadTrait updates a component as soon as the upload completes.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package.Other plugins' skills for the same job