gpt4 book ai didi

php - 有没有办法用 PHP 从 Google Cloud Storage 下载文件?而不仅仅是阅读它

转载 作者:搜寻专家 更新时间:2023-10-31 21:26:00 25 4
gpt4 key购买 nike

有没有一种方法可以使用 PHP 从 Google 云存储下载文件,而不是仅仅读取文件并使用 php 函数将内容保存到文件?? p>

我的代码是这样的:

        $obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);

$storage = new Google_Service_Storage($this->gcsClient);


$object = $storage->objects->get($this->bucket, $file);

$request = new Google_Http_Request($object['mediaLink'], 'GET');

$signed_request = $this->gcsClient->getAuth()->sign($request);
$http_request = $this->gcsClient->getIo()->makeRequest($signed_request);
$options = ['gs' => ['Content-Type' => 'text/plain']];

echo $http_request->getResponseBody();
$ctx = stream_context_create($options);
file_put_contents($destination, $http_request->getResponseBody(),0,$ctx);

我发现 Google Cloud Storage 支持上传。我使用 $storage->objects->insert(...) 效果很好,但我找不到类似的函数用于下载。

谢谢!

最佳答案

<?php
CloudStorageTools::serve('gs://mybucket/myfile.txt',
['save_as' => 'myfile.txt',
'content_type' => 'text/plain']););

另见 documentation和 Stuart Langley 的 answer对于这个问题。

关于php - 有没有办法用 PHP 从 Google Cloud Storage 下载文件?而不仅仅是阅读它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36055247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com