簡體   English   中英

在Google Cloud Storage對象上設置Cache-Control php客戶端

[英]Set Cache-Control php client on Google Cloud Storage Object

我遇到了這個問題,無法在網上找到一個簡單的工作php示例,可以在上傳到Google雲存儲時設置對象緩存控制。 我知道它在對象上有一個setMetadata,但是我不知道該怎么做。 使用gsutil不會削減它,因為它對於Web應用程序不是動態的。

到目前為止,這就是我所擁有的,但是setMetadata行引發了錯誤。 誰能幫忙改正那條線嗎? 請注意,在以下條件之前已經獲得了授權令牌

$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']
    );

我認為您想調用setCacheControl函數

這是一個工作示例:

$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']
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM