Support the ongoing development of →
posted 7 years ago
Last updated 1 year ago.
Last updated 7 years ago.

Thanks skido but Im not sure how to implement what is in that answer. Should I try setting different headers in the Cors.php or in the //FUCTION THAT GETS THE FILE section before ""return Response::download($s_path,$original_name, $headers); """



in this case

$file_db = Files::find($file_id);
$path = $file_db->file_path;
$original_name = $file_db->file_original_name;
$s_path = storage_path() . '/app/' . $path ;

$file = File::get($s_path);
if(!File::exists($s_path)) abort(404);

        $type = File::mimeType($s_path);
        $headers = array( 'Content-Type: ' . $type,);
     return Response::download($s_path,$original_name, $headers);

this is wrong: $headers = array( 'Content-Type: ' . $type,);

this array is used in the constructor of class Symfony\Component\HttpFoundation\HeaderBag

so it should be an associative array: $headers = [ 'Content-Type' => $type, ]

in this case:

    return $next($request)
    ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');

looks like you should write: return $next($request)->headers->set()

why? because $headers is a public property of BinaryFileResponse (inherited from Response), and it's type is ResponseHeaderBag. So you should call method set() to set header. :)


Hey Thanks alot skido! It worked =)


Sign in to participate in this thread!


Your banner here too?

tobbegd tobbegd Joined 30 Mar 2017


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.