0👍
You can do it like this:
public function show(File $file)
{
$path = storage_path('app/' . $file->getPath());
$headers = array(
'Content-Type: image/png',
);
return response()->download($path, $file->name, $headers);
}
Hope this helps!
0👍
Add headers :
public function show(File $file)
{
$path = storage_path('app/' . $file->getPath());
if(!file_exists($path)) throw new Exception("Can't get file");
$headers = array(
"Content-Disposition: attachment; filename=\"" . basename($path) . "\"",
"Content-Type: application/force-download",
"Content-Length: " . filesize($path),
"Connection: close"
);
return response()->download($path, $file->name, $headers);
}
OR
use custom download function must be like this :
function download($filepath, $filename = '') {
header("Content-Disposition: attachment; filename=\"" . basename($filepath) . "\"");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($filepath));
header("Connection: close");
readfile($filepath);
exit;
}
- [Vuejs]-Express and Vue. With axios, req.body is not working
- [Vuejs]-How to make Google Map reactive?
Source:stackexchange.com