Set Cache-Control on Google Cloud Storage bucket

0 views
Skip to first unread message

Rehoboth5467 via StackOverflow

unread,
Aug 26, 2015, 4:49:07 AM8/26/15
to google-appengin...@googlegroups.com

In support of the ops's question, I am sorry , none of the answers above satisfactorily solve the problem programmatically, particularly to a noob like me. I have run into the same 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.

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

Not being able to set cache control leaves one stuck on the 3600s google cache perpublic object write. Thanks in advance for the solution. Was going to post a fresh question but thought it better to improve this question-answer.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/25406410/set-cache-control-on-google-cloud-storage-bucket/32221832#32221832
Reply all
Reply to author
Forward
0 new messages