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
+23-23
Original file line number
Diff line number
Diff line change
@@ -1329,40 +1329,40 @@ The files will be available in a regular ``$request->files`` files bag::
1329
1329
.. _downloads:
1330
1330
1331
1331
Downloading files
1332
-
-----------------------
1332
+
-----------------
1333
1333
1334
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
1335
1336
1336
Create a LiveAction that generates the URL for the file download and returns a `RedirectResponse`::
1337
1337
1338
-
use Symfony\Component\HttpFoundation\RedirectResponse;
1339
-
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1340
-
use Symfony\UX\LiveComponent\Attribute\LiveAction;
1338
+
use Symfony\Component\HttpFoundation\RedirectResponse;
1339
+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1340
+
use Symfony\UX\LiveComponent\Attribute\LiveAction;
1341
1341
1342
-
// ...
1342
+
// ...
1343
1343
1344
-
class MyDownloadButton
1345
-
{
1346
-
// ...
1344
+
class MyDownloadButton
1345
+
{
1346
+
// ...
1347
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.
0 commit comments