【问题标题】:Set Cache-Control php client on Google Cloud Storage Object在 Google Cloud Storage 对象上设置 Cache-Control php 客户端
【发布时间】:2015-11-20 13:59:18
【问题描述】:

我遇到了这个问题,在网上找不到一个可以在上传到谷歌云存储时设置对象缓存控制的简单工作 php 示例。我知道它是对象上的 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']
    );

【问题讨论】:

    标签: php google-cloud-storage cache-control


    【解决方案1】:

    我想你想拨打setCacheControl function

    这是一个工作示例:

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

    【讨论】:

    • 好吧,这是一个 atart,但它的参数的正确格式是什么?如果我只是将 setMetadata 更改为 setCacheControl,则会收到错误 400 Required'。因此,以受影响的行为例,您可以使用正确的参数重写它以使代码正常工作吗?这个函数的使用格式可以在网上看到任何例子。
    • 我已经尝试过 "no-store", "private, max-age=0, no-transform","public, max-age=0, no-transform", "max-age= 0" 都无济于事,同样的错误 400 需要'响应
    • $obj->setCacheControl('Cache-Control: public, max-age=6000') 工作吗?
    • 仍然收到相同的错误 400 要求'。我想我之前尝试过,但没有成功.. 仍然停留在一个小时的缓存中。但我认为 setMetadata 会做到这一点..无论如何我只需要一些可以工作的东西,但是它可以工作。谢谢
    • 你可以试试把它设置在body里,像这样吗? ['name' => $file, 'mimeType' => 'text/html', 'data' => $infotowrite, 'uploadType' => 'media', 'cacheControl' => 'Cache-Control: public, max-age=6000']
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 2015-12-08
    • 2014-07-20
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 2014-01-30
    相关资源
    最近更新 更多