I'm developing an api in php with laravel framework that returns records for an ionic app. So the problem is that i send images and files paths and the app give an error when try to download the file with cross origin error
.
The method sends a json like this:
[{
"name": "Braga",
"ref": "6903",
"cover": "/images/uploads/0_C6903_597614930f57e.jpg",
"coverDetail": "/images/uploads/0_D6903_597614930f599.jpg",
"pdf": "/images/uploads/0_P6903_597614930f5b0.epub",
"companyId": "0"
}]
And I have another method(path) to get file:
public function getFile($url){
$file= public_path(). $url;
$headers = array(
'Content-Type: application/epub',
);
return Response::download($file, '', $headers);}
If did use that on browser it works, it downloads the file to my laptop but when I try to get the file to the app it gives me cross origin error
.
After searching about this I update my .htaccess
adding this lines:
<IfModule mod_headers.c>
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin"
Header always set Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</IfModule>
How can I solve this problem?
Thank you