You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/index.rst
+45
Original file line number
Diff line number
Diff line change
@@ -1326,6 +1326,51 @@ The files will be available in a regular ``$request->files`` files bag::
1326
1326
need to specify ``multiple`` attribute on HTML element and end ``name``
1327
1327
with ``[]``.
1328
1328
1329
+
.. _downloads:
1330
+
1331
+
Downloading files
1332
+
-----------------------
1333
+
1334
+
Currently, Live Components do not natively support returning file responses directly from a LiveAction. However, you can implement file downloads by redirecting to a route that handles the file response.
1335
+
1336
+
Create a LiveAction that generates the URL for the file download and returns a `RedirectResponse`::
1337
+
1338
+
use Symfony\Component\HttpFoundation\RedirectResponse;
1339
+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1340
+
use Symfony\UX\LiveComponent\Attribute\LiveAction;
1341
+
1342
+
// ...
1343
+
1344
+
class MyDownloadButton
1345
+
{
1346
+
// ...
1347
+
1348
+
#[LiveAction]
1349
+
public function initiateDownload(UrlGeneratorInterface $urlGenerator): RedirectResponse
When Turbo is enabled, it will intercept the redirect and initiate a second request for the download URL. Adding `data-turbo="false"` ensures that the download URL is called only once.
1368
+
1369
+
.. note::
1370
+
1371
+
Native support for file downloads in Live Components is under development. For more details, refer to the related `pull request #2483 <https://github.com/symfony/ux/pull/2483>`_.
0 commit comments