titasgailius / laravel-stream-remote
流式传输远程文件
1.0.0
2020-05-25 12:36 UTC
Requires
- guzzlehttp/guzzle: ~6.0
- illuminate/routing: ^7.0|^6.0|^5.7
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2024-09-19 22:59:38 UTC
README
使用此包,您可以直接从Laravel应用程序中流式传输远程内容。
安装
composer require titasgailius/laravel-stream-remote
使用
可以使用 streamRemoteDownload
方法生成一个响应,将远程资源的内容转换为可下载的响应,而无需将任何内容写入磁盘。
此方法接受一个URL、文件名和一个可选的包含头信息的数组作为参数。
return response()->streamRemoteDownload('https://example.com/remote/file.zip', 'archive.zip');
高级
您可以指定响应的头信息、内容-disposition值和流式内容的数据块大小。
return response()->streamRemoteDownload('https://example.com/remote/file.zip', 'archive.zip', [ 'Content-Type' => 'application/zip' ], 'attachment', 1024);
这是 streamRemoteDownload
方法的完整签名。
public function streamRemoteDownload( string $url, string $name = null, array $headers = [], string $disposition = 'attachment', int $chunk = 2048 ): StreamedResponse;
测试
此包包含测试,存储在 tests
目录中。运行 ./vendor/bin/phpunit
以运行测试套件。