[英]How to download a large private file from Google Storage API with PHP?
我正在尝试允许通过经过身份验证的PHP从Google Storage API将大文件下载到客户端。
我能够使用以下代码读取/下载小文件:
$object = $storage->objects->get($bucket, 'filename');
$request = new GuzzleHttp\Psr7\Request('GET', $object['mediaLink']);
//authorize the request before sending
$http = $client->authorize();
$response = $http->send($request);
$body = $response->getBody()->read($object->getSize());
$ body将具有文件的全部内容,但其中一些可能为1gb。
尝试使用:
$stream = Psr7\stream_for($response->getBody());
但这是行不通的。
如何将文件下载流传输到客户端而不将其加载到内存中?
谢谢。
考虑向客户端发送一个已签名的URL,以便直接从Google Cloud Storage提供内容,而不是尝试自己代理下载的整个文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.