Saq*_*eib 3 php amazon-s3 laravel
我正在将文件上传到s3我希望使用控制器中的以下代码安全地下载它,但它不起作用。
我正在使用 Laravel 5.5,文件可见性在s3.
if( Storage::disk('s3')->exists($file_path) ) {
$file = Storage::disk('s3')->get($file_path);
return response()->download($file);
}
abort(404, 'File not found.');
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误
is_file() expects parameter 1 to be a valid path, string given
...
/home/vagrant/spark-etr/vendor/symfony/http-foundation/File/File.php:36
#1 /home/vagrant/spark-etr/vendor/symfony/http-foundation/File/File.php(36): is_file('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...')
#2 /home/vagrant/spark-etr/vendor/symfony/http-foundation/BinaryFileResponse.php(94): Symfony\\Component\\HttpFoundation\\File\\File->__construct('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...')
#3 /home/vagrant/spark-etr/vendor/symfony/http-foundation/BinaryFileResponse.php(53): Symfony\\Component\\HttpFoundation\\BinaryFileResponse->setFile('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...', 'attachment', false, true)
#4 /home/vagrant/spark-etr/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(125): Symfony\\Component\\HttpFoundation\\BinaryFileResponse->__construct('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...', 200, Array, true, 'attachment')
Run Code Online (Sandbox Code Playgroud)
该文件已打开s3,因为我在下载之前检查是否存在。
转储$filevar 给我这样的二进制文件
请帮忙
尝试
if( Storage::disk('s3')->exists($file_path) ) {
$file = Storage::disk('s3')->get($file_path);
$headers = [
'Content-Type' => 'your_content_type',
'Content-Description' => 'File Transfer',
'Content-Disposition' => "attachment; filename={$yourFileName}",
'filename'=> $yourFileName
];
return response($file, 200, $headers);
}
Run Code Online (Sandbox Code Playgroud)
更新
您可以阅读有关下载large文件的
更多信息 为什么在 Laravel 中不能轻松下载大文件?
| 归档时间: |
|
| 查看次数: |
4232 次 |
| 最近记录: |