Php 如何将文件上传到谷歌云存储,并将其设置为公共权限并获取链接

Php 如何将文件上传到谷歌云存储,并将其设置为公共权限并获取链接,php,google-cloud-storage,google-cloud-platform,Php,Google Cloud Storage,Google Cloud Platform,我正在将文件上传到谷歌云存储,我想上传具有公共权限的文件,如果可能的话,还想获得回复链接 现在我只是上传 我的代码 require_once dirname(dirname(__FILE__)).'/vendor/autoload.php'; $client = new Google_Client(); $client->setAuthConfig('/blabla.json'); $client->useApplicationDefaultCredentials(); $clie

我正在将文件上传到谷歌云存储,我想上传具有公共权限的文件,如果可能的话,还想获得回复链接

现在我只是上传

我的代码

require_once  dirname(dirname(__FILE__)).'/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('/blabla.json');
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$storage = new Google_Service_Storage($client);
$fileTmpName="blabla.jpg";
$file_name = "bodzin";
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file_name);
$storage->objects->insert(
"creatives_new",
$obj,
['name' => $file_name, 'data' => file_get_contents($fileTmpName),'uploadType' => 'media']
);
我发现了这颗宝石:

还有一件有趣的事情值得注意,那就是链接似乎永远都是
/

我知道API文档非常好,但我找不到(你明白了吗?我也面临同样的挑战。
use Google\Cloud\Storage\StorageClient;

/**
* Make an object publically accessible.
*
* @param string $bucketName the name of your Cloud Storage bucket.
* @param string $objectName the name of your Cloud Storage object.
*
* @return void
*/
function make_public($bucketName, $objectName)
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->object($objectName);
    $object->update(['acl' => []], ['predefinedAcl' => 'PUBLICREAD']);
    printf('gs://%s/%s is now public' . PHP_EOL, $bucketName, $objectName);
}