写这个的原因,在使用 cos 做文件存储时,官方所推的Storage::download 无法下载文件(文件其实是可以正常访问的)。
下面是官方的方法:
return Storage::download('file.jpg');
return Storage::download('file.jpg', $name, $headers);
最后的解决方法,使用 官方的 `response()->make`
$filename = basename(request('url'));
$content = file_get_contents(request('url'));
return response()->make($content, 200, [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="'.$filename,
'Content-Transfer-Encoding' => 'binary'
]);
网友评论