本文介绍了在Google Cloud Storage Object上设置Cache-Control php客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了这个问题,无法在线找到一个简单的工作php示例,该示例可以在上传到Google云存储时设置对象缓存控制。我知道它在对象上有一个setMetadata,但是我不知道该怎么做。使用gsutil不会削减它,因为它对于Web应用程序不是动态的。
I have run into this problem and cant find a simple working php example online that can set the object cache-control while uploading to google cloud storage. I know its a setMetadata on object, but I am lost how to do it. using gsutil doesnt cut it because it is not dynamic for a web app.
到目前为止,这是我所拥有的,但是setMetadata行会引发错误。谁能帮忙改正那条线吗?请注意,已经在以下
So far, this is what I have but the setMetadata line throws errors. Can anyone please help correct that line? Note that authorisation token already obtained before the below
$file = "xxx.html";
$infotowrite = "999";
$service = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$obj->setMetadata(['cacheControl' => 'public', 'max-age' => '6000']);
$results = $service->objects->insert(
$bucket_name,
$obj,
['name' => $file, 'mimeType' => 'text/html', 'data' => $infotowrite, 'uploadType' => 'media']
);
推荐答案
我认为您想致电。
这是一个工作示例:
$bucket_name = 'my-bucket';
$file = "xxx.html";
$infotowrite = "999";
$service = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$obj->setCacheControl('public, max-age=6000');
$results = $service->objects->insert(
$bucket_name,
$obj,
['name' => $file, 'mimeType' => 'text/html', 'data' => $infotowrite, 'uploadType' => 'media']
);
这篇关于在Google Cloud Storage Object上设置Cache-Control php客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!