Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NickNorth's avatar

Streaming file download from Nova action

I want to stream a file download from a Nova action. This GiHub issue raises the problem, and is marked as having been implemented, but I can't find anything saying how to go about it. Does anyone know how to do this?

0 likes
3 replies
tisuchi's avatar

@nicknorth Does it help you?

public function downloadFile($file)
    {
        $path = storage_path("app/public/{$file}");
        return response()->streamDownload(function () use ($path) {
            readfile($path);
        }, $file);
    }
NickNorth's avatar

Thanks @tisuchi, but unfortunately this does not work within a Nova action. The action's handle function seems to require an array return e.g. Action::download gives ['download' => $url, 'name' => $name] to download a file from an action. So maybe there is some other set of keys and values that will make it stream the download rather than looking for a file to fetch.

NickNorth's avatar

I think it needs something along the lines of Laravel\Nova\Actions\ExportAsCsv, which has a dispatchRequestUsing function that does the work, but I've been unable to apply it in my case.

1 like

Please or to participate in this conversation.