简体   繁体   English

如何使用PHP从Google Storage API下载大型私有文件?

[英]How to download a large private file from Google Storage API with PHP?

I'm trying to allow download of large files to clients, from Google Storage API behind an authenticated PHP. 我正在尝试允许通过经过身份验证的PHP从Google Storage API将大文件下载到客户端。

I was able to read/download small files using the following code: 我能够使用以下代码读取/下载小文件:

$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 will have the entire content of the file, but some of those might be 1gb size. $ body将具有文件的全部内容,但其中一些可能为1gb。

Tried using: 尝试使用:

$stream = Psr7\stream_for($response->getBody());

But it doesn't work. 但这是行不通的。

How would I be able to stream the download of the file to the client without loading it in memory? 如何将文件下载流传输到客户端而不将其加载到内存中?

Thanks. 谢谢。

考虑向客户端发送一个已签名的URL,以便直接从Google Cloud Storage提供内容,而不是尝试自己代理下载的整个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM