laravel - Laravel Storage::从Gmail url下载不起作用
问题描述
在我的 Laravel 5.8 应用程序中,我动态生成 url 以下载存储在storage
目录下的文档。
我通过电子邮件发送生成的 url,因此用户可以单击它以下载文件。
在浏览器中直接引入接收到的链接时,生成的文件被正确下载。但是,从 gmail 邮箱中单击它时,会打开一个新选项卡,并在一秒钟后关闭而不下载文件。
路由web.php
文件:
Route::get('download/{path}', ['as' => 'downloadStorage', 'uses' => 'AppController@downloadStorage'])
->where('path', '.*')->middleware('auth');
我的控制器代码:
public function downloadStorage($path)
{
$user = \Auth::user();
// Here I have some code that verify that user is logged
// and has permissions to download this file
$hasPermission = true;
if ($hasPermission) {
return Storage::download($path); // <-- THIS LINE IS REACHED CORRECTLY
} else {
return abort(403);
}
}
知道如何解决这个问题吗?
我的猜测是,在将文件提供给浏览器之前,新选项卡已关闭(由于return
),但我无法找到任何解决方案。
解决方案
我不确定为什么应用程序无法提供文件以供下载,但是我找到了以下解决方案:
而不是为downliading提供文件:
return Storage::download($path);
我将其退回,以便在新选项卡中打开它:
return \Response::file(Storage::path($path));
推荐阅读
- c# - 匹配字符串数组和字符串列表的一种方法
- python - Python游戏地图
- tensorflow - 如何在自定义成本函数中访问 y_true 值?
- php - MySQL查询和PHP输入之间的比较
- go - 在 JSON Binding 中处理省略值 (int) 时生成错误
- apache-nifi - 无法从 Nifi 在 ignite DB 中插入数据
- error-handling - 便携使用make-instance做条件?
- elixir - 基于payload的Phoenix路由
- node.js - NodeJs 从 Firebase 存储中删除文件
- count - MariaDB:使用 COUNT(*) OVER() 时出现错误 1064