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

190
Views
Devolver la descarga de archivos desde el almacenamiento en Laravel

Me gustaría poder recuperar un archivo del almacenamiento en mi controlador.

 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; } }

Ahora, puedo obtener la ruta correctamente, sin embargo, todo lo que sale es un galimatías, como si estuvieras mirando una imagen sin la extensión.

Idealmente, me gustaría que esto funcione como una especie de "guardar como".

¿Cómo puedo hacer esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe utilizar una respuesta de descarga de archivos .

 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)); } }

Es una mala práctica devolver solo una cadena. Al usar las respuestas de Laravel, Laravel se asegura de que los encabezados y otros requisitos estén configurados correctamente para devolver la respuesta al navegador.

over 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!