Php 关于缓存控制

Php 关于缓存控制,php,google-cloud-storage,Php,Google Cloud Storage,是否有任何方法可以将bucket中的所有文件设置为具有默认缓存控件public和public,max age=7776000?如果不是,我应该如何调整我的PHP代码以使用多部分上传 这是我的媒体上传代码: $file_up = file_get_contents($file['full_path']); clearstatcache(); $file['size'] = filesize($file['full

是否有任何方法可以将bucket中的所有文件设置为具有默认缓存控件public和public,max age=7776000?如果不是,我应该如何调整我的PHP代码以使用多部分上传

这是我的媒体上传代码:

$file_up            = file_get_contents($file['full_path']);

clearstatcache();                        

$file['size']       = filesize($file['full_path']);
$access_token       = $this->googleapi->get_access_token();                             

$header = array(
    'Content-Type: audio/mp3',
    'Content-Length: '.$file['size'].''
);

$url    = "https://www.googleapis.com/upload/storage/v1/b/MY_BUCKET/o?uploadType=media&predefinedAcl=publicRead&name=".$file['name_ext'].'&access_token='.$access_token;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file_up);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
$dxa = curl_exec($ch);
curl_close($ch);
您需要将“cacheControl”属性设置为上载的一部分。要做到这一点,您需要执行
多部分
可恢复
上传类型,并将cacheControl设置为分配的元数据的一部分。请按照以下指南操作:

也就是说,通过以下方式,这将更容易实现:


也许使用官方的谷歌云存储SDK会更容易些?
$options = [
    'name' => '/images/new-name.jpg',
    'metadata' => [
       'cacheControl' => 'public,max-age=7776000'
]];
$object = $bucket->upload(
    fopen(__DIR__ . '/image.jpg', 'r'),
    $options);