{"slug":"ux-upload","title":"ux-upload","summary":"Symfony UX Upload: replace FileType with UploadType for image previews, drag and drop, dropzones, clipboard paste, client-side file validation, progress bars, background file uploads, chunking, pause and resume, and uploads that survive form validation errors.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-02T16:48:40.453188Z","repo":{"url":"https://github.com/smnandre/symfony-ux-skills","stars":191,"forks":15,"license":"MIT","updatedAt":"2026-12-02T03:34:06Z"},"bodyHtml":"<hr>\n<h2>name: ux-upload\ndescription: 'Symfony UX Upload: replace FileType with UploadType for image previews, drag and drop, dropzones, clipboard paste, client-side file validation, progress bars, background file uploads, chunking, pause and resume, and uploads that survive form validation errors.'\nlicense: MIT\nmetadata:\nauthor: Simon André\nurl: <a href=\"https://smnandre.dev\">https://smnandre.dev</a></h2>\n<h1>UX Upload</h1>\n<p>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. <code>UploadType</code> replaces <code>FileType</code> and returns an <code>UploadedFile</code> that extends HttpFoundation's, so <code>move()</code> keeps working.</p>\n<p>Since Symfony UX 3.8+. The package is <strong>experimental</strong>: its API may still change.</p>\n<h2>Installation</h2>\n<pre><code>composer require symfony/ux-upload\n</code></pre>\n<p>Until a Flex recipe exists, register the bundle and the routes yourself:</p>\n<pre><code>// config/bundles.php\nSymfony\\UX\\Upload\\UXUploadBundle::class =&gt; ['all' =&gt; true],\n</code></pre>\n<pre><code># config/routes/ux_upload.yaml\nux_upload:\n    resource: '@UXUploadBundle/config/routes.php'\n    prefix: /_ux/upload\n    trailing_slash_on_root: false\n</code></pre>\n<p>Requires StimulusBundle. Assets: <code>php bin/console importmap:install</code> (AssetMapper) or <code>npm install &amp;&amp; npm run dev</code> (Encore, Reprise). The stylesheet is opt-in (see Styling). Schedule cleanup from day one:</p>\n<pre><code>*/15 * * * * cd /path/to/app &amp;&amp; php bin/console ux:upload:cleanup --age=24h\n</code></pre>\n<p><strong>Every upload needs an identity.</strong> 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).</p>\n<p>If several application nodes handle uploads, read the <a href=\"references/reference.md#distributed\">distributed deployment configuration</a> for shared storage and locking.</p>\n<h2>Quick Start</h2>\n<pre><code># config/packages/ux_upload.yaml\nux_upload:\n    uploaders:\n        documents:\n            max_size: 50M\n            allowed_types: [application/pdf]\n</code></pre>\n<pre><code>use Symfony\\UX\\Upload\\Form\\UploadType;\n\n$builder\n    -&gt;add('document', UploadType::class, [\n        'uploader' =&gt; 'documents',\n        'constraints' =&gt; [new NotBlank()],\n    ])\n    -&gt;add('title', TextType::class, ['constraints' =&gt; [new NotBlank()]]);\n</code></pre>\n<pre><code>use Symfony\\UX\\Upload\\Upload\\UploadedFile;\n\nif ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {\n    /** @var UploadedFile|null $upload */\n    $upload = $form-&gt;get('document')-&gt;getData();\n    if (null !== $upload) {\n        $upload-&gt;move($directory, $upload-&gt;getId().'.'.($upload-&gt;guessExtension() ?? 'bin'));\n    }\n\n    return $this-&gt;redirectToRoute('document_new');\n}\n</code></pre>\n<p>Render with <code>form_row(form.document)</code> as usual. Name the final file from <code>getId()</code>: repeated submissions hit the same target, and client filenames stay out of the way.</p>\n<h2>Field Options</h2>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Default</th>\n<th>Notes</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>uploader</code></td>\n<td><code>default</code></td>\n<td>Named server policy</td>\n</tr>\n<tr>\n<td><code>max_size</code></td>\n<td><code>null</code></td>\n<td>Inherits the uploader; may only narrow it</td>\n</tr>\n<tr>\n<td><code>allowed_types</code></td>\n<td><code>[]</code></td>\n<td>MIME list; may only narrow the uploader</td>\n</tr>\n<tr>\n<td><code>multiple</code></td>\n<td><code>false</code></td>\n<td>Returns <code>list&lt;UploadedFile&gt;</code></td>\n</tr>\n<tr>\n<td><code>max_files</code></td>\n<td><code>null</code></td>\n<td>Count limit with <code>multiple</code></td>\n</tr>\n<tr>\n<td><code>layout</code></td>\n<td><code>compact</code></td>\n<td><code>compact</code> or <code>dropzone</code></td>\n</tr>\n<tr>\n<td><code>show_preview</code></td>\n<td><code>false</code></td>\n<td>Image previews</td>\n</tr>\n<tr>\n<td><code>auto_upload</code></td>\n<td><code>true</code></td>\n<td>Start right after selection</td>\n</tr>\n<tr>\n<td><code>compression</code></td>\n<td><code>false</code></td>\n<td>gzip bodies and chunks (also needs the uploader)</td>\n</tr>\n<tr>\n<td><code>widget_attr</code></td>\n<td><code>[]</code></td>\n<td>Attributes on the widget container (<code>attr</code> goes to the native input)</td>\n</tr>\n<tr>\n<td><code>help_text</code>, <code>invalid_message</code></td>\n<td>generated</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>Required and mapped by default, like <code>FileType</code>; pass <code>required: false</code> for an optional file.</p>\n<p>For dropzones, previews and client-side presentation, see <a href=\"https://symfony.com/bundles/ux-upload/current/customization.html\">customizing the upload field</a>. To react to progress, completion or validation errors in Stimulus, see the <a href=\"references/reference.md#browser\">browser events reference</a>.</p>\n<h2>Named Uploaders</h2>\n<pre><code>ux_upload:\n    max_size: 100M                  # global limit, 0 disables it\n    uploaders:\n        avatars:\n            max_size: 5M\n            allowed_types: [image/jpeg, image/png, image/webp]\n            chunk_size: 1M\n            completed_ttl: 3600\n        documents:\n            max_size: 100M\n            allowed_types: [application/pdf]\n</code></pre>\n<p>The uploader name is signed into the policy and the token: a token from another uploader is rejected. Overridable per uploader: <code>max_size</code>, <code>allowed_types</code>, <code>chunk_size</code>, <code>parallel_chunks</code>, <code>compression</code>, <code>integrity_algorithm</code>, <code>completed_ttl</code>, <code>max_pending_per_owner</code>.</p>\n<h2>Saving Files</h2>\n<p><code>UploadedFile</code> is a <strong>temporary</strong> reference. Copy it into your own storage, then record the final location:</p>\n<pre><code>$stream = $upload-&gt;openStream();       // no local copy, works with Flysystem\ntry {\n    $attachment = $this-&gt;storage-&gt;storeOnce($upload-&gt;getId(), $stream, $upload-&gt;getClientOriginalName());\n} finally {\n    fclose($stream);\n}\n</code></pre>\n<ul>\n<li>Make saving idempotent on <code>getId()</code> (double click, proxy retry). Under concurrency, enforce it with a unique constraint rather than a lookup before the write.</li>\n<li>Never call <code>delete()</code> in the same request: a second valid submission may still need the stream. Let <code>ux:upload:cleanup</code> remove it after <code>completed_ttl</code>.</li>\n<li>Never persist <code>getStoragePath()</code>; cleanup deletes that path.</li>\n<li>Metadata getters (<code>getClientOriginalName()</code>, <code>getMimeType()</code>, <code>getSize()</code>, <code>getChecksum()</code>...) never touch the file: they read signed data. <code>getPathname()</code>, <code>getContent()</code>, the <code>File</code>/<code>Image</code> constraints and the dev profiler copy the whole file locally first.</li>\n</ul>\n<h2>Security</h2>\n<pre><code>use Symfony\\Component\\HttpFoundation\\RequestStack;\nuse Symfony\\UX\\Upload\\Security\\UploadContext;\nuse Symfony\\UX\\Upload\\Security\\UploadContextResolverInterface;\n\nfinal class SessionUploadContextResolver implements UploadContextResolverInterface\n{\n    public function __construct(private readonly RequestStack $requestStack) {}\n\n    public function resolve(): UploadContext\n    {\n        $request = $this-&gt;requestStack-&gt;getMainRequest();\n        if (null === $request || !$request-&gt;hasSession()) {\n            return new UploadContext();\n        }\n\n        $session = $request-&gt;getSession();\n        $owner = $session-&gt;get('upload_owner');\n        if (!\\is_string($owner) || '' === $owner) {\n            $owner = bin2hex(random_bytes(16));\n            $session-&gt;set('upload_owner', $owner);\n        }\n\n        return new UploadContext(ownerId: $owner);\n    }\n}\n</code></pre>\n<pre><code># config/services.yaml\nservices:\n    Symfony\\UX\\Upload\\Security\\UploadContextResolverInterface:\n        alias: App\\Upload\\SessionUploadContextResolver\n</code></pre>\n<p>Tokens are bound to owner, tenant, form field and uploader, and signed with <code>kernel.secret</code>. <code>allow_anonymous: true</code> shares one context (and one quota) between all visitors: only with a <code>rate_limiter</code>. CSRF is checked automatically when <code>symfony/security-csrf</code> is installed.</p>\n<h2>Live Components</h2>\n<pre><code>use Symfony\\UX\\Upload\\LiveComponent\\Attribute\\UploadTarget;\nuse Symfony\\UX\\Upload\\LiveComponent\\ComponentWithUploadTrait;\n\n#[AsLiveComponent]\nfinal class ProfilePhoto\n{\n    use ComponentWithUploadTrait;\n    use DefaultActionTrait;\n\n    #[LiveProp]\n    #[UploadTarget(uploader: 'avatars')]\n    public ?string $photo = null;          // nullable string: holds the signed token\n\n    public function getPhotoUpload(): ?UploadedFile\n    {\n        return $this-&gt;getUpload('photo');\n    }\n}\n</code></pre>\n<pre><code>&lt;div{{ attributes.defaults(stimulus_controller('symfony/ux-upload/live-upload', {property: 'photo'})) }}&gt;\n    {{ form_row(this.uploadForm.photo) }}   {# an UploadType built with 'data' =&gt; this.photoUpload #}\n&lt;/div&gt;\n</code></pre>\n<p>The bridge calls the <code>applyUpload</code> action on upload completion; <code>clearUpload</code> deletes the temporary file and nulls the property. Keep the field out of <code>data-live-ignore</code>.</p>\n<h2>Styling</h2>\n<p>Opt in to the stylesheet in <code>assets/controllers.json</code> (<code>\"@symfony/ux-upload/dist/style.min.css\": true</code> under the <code>upload</code> controller's <code>autoimport</code>), then theme with <code>--ux-upload-accent</code>, <code>--ux-upload-bg</code>, <code>--ux-upload-border</code>, <code>--ux-upload-radius</code>... Without it, the native file input stays visible and usable, and your form theme rules. To change markup, <code>{% use '@UXUpload/form_theme.html.twig' %}</code> in your own form theme and override blocks (<code>ux_upload_actions</code>, <code>ux_upload_item</code>...) keeping the <code>data-ux-upload-*</code> hooks.</p>\n<h2>Key Principles</h2>\n<p><strong>Configure policy on named uploaders; fields only narrow it.</strong></p>\n<p><strong>Identify every visitor.</strong> Logged-in user, a session resolver, or a deliberate <code>allow_anonymous</code> with rate limiting.</p>\n<p><strong>Temporary is temporary.</strong> Copy with <code>openStream()</code> or <code>move()</code>, persist idempotently, let cleanup delete.</p>\n<p><strong>Fit <code>chunk_size</code> to PHP and proxy limits.</strong> Files up to <code>chunk_size</code> go in one multipart POST; larger files go in chunks.</p>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://ux.symfony.com/upload\">Symfony UX package page</a> (<a href=\"https://ux.symfony.com/upload.md\">Markdown summary</a>) · <a href=\"https://packagist.org/packages/symfony/ux-upload\"><code>symfony/ux-upload</code> on Packagist</a>.</li>\n<li>For field customization, validation, retries and deployment, see the <a href=\"https://symfony.com/bundles/ux-upload\">Symfony UX Upload documentation</a> or its <a href=\"https://raw.githubusercontent.com/symfony/ux/3.x/src/Upload/doc/index.rst\">RST source</a>.</li>\n<li><strong>Reference</strong> (configuration, <code>UploadedFile</code> API, server and DOM events, JavaScript <code>Uploader</code>, form theme blocks, storage backends, testing): <a href=\"references/reference.md\">references/reference.md</a></li>\n<li><strong>Gotchas</strong> (installation, limits, tokens, production, debugging): <a href=\"references/gotchas.md\">references/gotchas.md</a></li>\n</ul>\n<h3>Demos</h3>\n<p>Each demo shows the code behind the example. <a href=\"https://ux.symfony.com/demos/upload\">Upload demo catalog</a></p>\n<ul>\n<li><a href=\"https://ux.symfony.com/demos/upload/keep-files\">Keep Files on Errors</a></li>\n<li><a href=\"https://ux.symfony.com/demos/upload/turbo\">Upload with Turbo</a></li>\n<li><a href=\"https://ux.symfony.com/demos/upload/live-avatar\">Live Avatar</a></li>\n<li><a href=\"https://ux.symfony.com/demos/upload/input\">Simple &amp; Enhanced Input</a></li>\n<li><a href=\"https://ux.symfony.com/demos/upload/dropzone\">Dropzone &amp; Card Grid</a></li>\n<li><a href=\"https://ux.symfony.com/demos/upload/resumable\">Resumable Large Files</a></li>\n</ul>\n<p>The package page also embeds a <a href=\"https://ux.symfony.com/upload#try\">PDF form that keeps its file after validation errors</a> and a <a href=\"https://ux.symfony.com/upload#field\">photo grid with image previews</a>.</p>\n<h2>See Also</h2>\n<ul>\n<li><strong>live-component</strong>: <code>ComponentWithUploadTrait</code> updates a component as soon as the upload completes.</li>\n<li><strong>ux-image</strong>: serve the saved images through an image CDN.</li>\n</ul>\n","files":[{"path":"references/gotchas.md","sizeBytes":4686,"isText":true},{"path":"references/reference.md","sizeBytes":9271,"isText":true},{"path":"SKILL.md","sizeBytes":10557,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-02T16:49:40.630293Z","sha256":"FDC1C60C6299E1191F65FC4805892F1EE4D5AF963DA211BC2D71D80120F2BBF7","sizeBytes":10784},"review":null,"source":{"repositoryUrl":"https://github.com/smnandre/symfony-ux-skills","path":"skills/ux-upload","license":"MIT","commit":"78c25ed0b79bcc21d7611002dc81d8b87c3316e2","subtreeSha":"2BC46EF72792253DFC0B305E739B4D68828FC1E37C00611A5A6B2AB311499AE9","lastSyncedAt":"2026-12-02T16:48:36.132977Z"},"reviewedAt":"2026-12-02T16:51:34.797808Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/smnandre/symfony-ux-skills/tree/main/skills/ux-upload"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install smnandre-symfony-ux-skills@llmmart"},{"target":"git","command":"git clone https://github.com/smnandre/symfony-ux-skills.git"}]}