laravel - 从谷歌驱动器(文件系统)或(隐藏链接中的 api 密钥)下载 Laravel
问题描述
第一种下载方式:
将我的 API KEY 放入链接中,我可以直接从我的谷歌驱动器下载文件。但我不想将我的 API_KEY 提供给用户。
2.我也可以通过其他方式访问我的驱动器:(
using nao-pon/flysystem-google-drive
)
Route::get('/download/{rest?}', function ($rest) {
$metadata = Storage::cloud()->getMetadata($rest);
$readStream = Storage::cloud()->getDriver()->readStream($rest);
return response()->stream(function () use ($readStream) {
fpassthru($readStream);
}, 200, [
'Content-Type' => $metadata['mimetype'],
'Content-disposition' => 'attachment; filename="'.$metadata['name'].'"', // force download?
]);
})->where('rest','(.*)');
这样我就不必使用 api_key 但服务器必须下载整个文件,它是一个流,但仍然使用服务器资源。
另一方面https://www.googleapis.com/drive/v3/files/1YIH4zfM0P1xa-_mfZNGiIY8qZrIEt-rF/?key=API_KEY&alt=media
需要内容类型和文件名,因为它没有。而且我不知道如何隐藏 api 密钥。
那么你有什么建议。有没有其他方法不响应()->流不通过服务器逐流下载整个文件,然后将其发送给用户?多个用户下载文件会占用所有带宽,所以下载速度下降如此之快。
解决方案
推荐阅读
- javascript - 这是 shouldComponentUpdate 的合理实现吗?
- eclipse - 当我从 maket 位置在 Eclipse 中安装 glassFish 工具时,出现错误,例如解决方案不可用
- javascript - 如何将 postcss 结果设置/返回给变量?
- variables - TCL regsub 到变量?
- javascript - 在 IOS 上下载捕获的图像
- html - 将 CSS 填充与 SVG 或单独的 SVG 一起使用是否更高效?
- performance - 在 Unity 中使用 SetAsFirstSibling 还是 SetAsLastSibling 更好?
- javascript - Angular http 流双重请求 [GET,HEAD]
- git - 使用 Dockerfile RUN 克隆 bitbucket 存储库
- python - Python 2.7:如何弥补缺少的 pool.starmap?