Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Return file download from storage in Laravel

I'd like to be able to retrieve a file from storage in my controller.

public function getFile($fileID) {
    $file = CommUploads::where('id', $fileID)->first();

    if (Auth::user()->id == $file->user_id || Auth::user()->id == $file->artist_id) {
        $fileGet = Storage::get($file->file_path);
        return $fileGet;
    }
}

Now, I'm able to get the path correctly, however, all that comes out is gibberish, as if you're looking at an image without the extension.

Ideally I'd like this to work as a "save as" sort of thing.

How can I do this?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should use a file download response.

public function getFile($fileID) {
    $file = CommUploads::where('id', $fileID)->first();

    if (Auth::user()->id == $file->user_id || Auth::user()->id == $file->artist_id) {
        return response()->download(storage_path('app/' . $file->file_path));
    }
}

It's bad practice to return just a string. When using Laravel responses, Laravel makes sure the headers and other requirements are set correctly to return the response to the browser.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!