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
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. :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community