Support the ongoing development of Laravel.io →
posted 7 years ago
Security
Last updated 2 years ago.
0
Last updated 7 years ago.
0

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

Thanks

0

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-Origin','*')
    ->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. :)

0

Hey Thanks alot skido! It worked =)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

tobbegd tobbegd Joined 30 Mar 2017

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.