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

devondahon's avatar

How to pass private file to API

I'm trying to download a private file from my API, but I'm only getting part of it (the last line).

Here is what I'm doing:

Route::get('mydata/download', fn (Request $request) => response()->download(storage_path('foo' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'myfile.csv')));

What the correct way to access and return a private file ?

0 likes
5 replies
MohamedTammam's avatar

What's the result of storage_path('foo' . DIRECTORY_SEPARATOR . 'bar' . DIRECTORY_SEPARATOR . 'myfile.csv')? is that the full physical path of the file?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@devondahon Start by testing it by just downloading it directly in the browser by visiting the url. If that works as expected, you can show the axios code, as the laravel part works. As far as I know handling downloads with only JS can be quite tricky.

Please or to participate in this conversation.