简体   繁体   中英

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.

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.

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提供内容,而不是尝试自己代理下载的整个文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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