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

ayoub19's avatar

File Download Issue in Laravel 11 with Inertia and Vue

I'm using Laravel 11 with Inertia and Vue. In one of my controllers, I have a method to download files: public function downloadFile($id){ $file = File::find($id); return Storage::download($file['path']); } Laravel doesn't give any errors, but when I call this method, it redirects me to the page I was on, and the file doesn't get downloaded - it's as if nothing happened. I've also tried using response(Storage::download($file['path'])), but then a popup tells me: HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Disposition: attachment; filename=file1.PNG Content-Length: 2332 Content-Type: image/png What could be causing this issue, and how can I fix it?

0 likes
3 replies
Amaury's avatar

@ayoub19 Hi. You have to pass content-type argument to the response download method.

It should looks like that to download the my-image.png:

return response()->download(
    'path/to/storage/my-image.png', 
    'my-image.png',
    [
        'Content-Type' => 'application/octet-stream',
        'Content-Disposition' => 'attachment; filename="my-image.png"',
    ]
);
ayoub19's avatar

@Amaury thanks amaury but the problem was using router.get("url") instead of window.open("url")

ayoub19's avatar

Instead of using router.get("url"), I used window.open("url"), and everything seems to be working fine now.

Please or to participate in this conversation.