Is it possible to change headers on an S3 object without downloading the entire object?

后端 未结 6 1824
悲哀的现实
悲哀的现实 2020-12-08 09:59

I\'ve uploaded a bunch of images to Amazon S3, and now want to add a Cache-Control header to them.

Can the header be updated without downloading the entire image? I

6条回答
  •  爱一瞬间的悲伤
    2020-12-08 10:44

    with the amazon aws-sdk, Doing a copy_object with extra headers seems to do the trick for setting caching control headers for an existing S3 Object.

    =====================x===============================================

     "aws-key" , "secret" => "aws-secret") ;
    
    
            $s3 = new AmazonS3($options);
            $bucket = "bucket.3mik.com" ;
    
    
        $exists = $s3->if_bucket_exists($bucket);
        if(!$exists) {
            trigger_error("S3 bucket does not exists \n" , E_USER_ERROR);
        }
    
        $name = "cows-and-aliens.jpg" ;
        echo " change headers for $name  \n" ;
        $source = array("bucket" => $bucket, "filename" => $name);
        $dest = array("bucket" => $bucket, "filename" => $name);
    
        //caching headers
        $offset = 3600*24*365;
        $expiresOn = gmdate('D, d M Y H:i:s \G\M\T', time() + $offset);
        $headers = array('Expires' => $expiresOn, 'Cache-Control' => 'public, max-age=31536000');
    
           $meta = array('acl' => AmazonS3::ACL_PUBLIC, 'headers' => $headers);
    
        $response = $s3->copy_object($source,$dest,$meta);
        if($response->isOk()){
            printf("copy object done \n" );
    
        }else {
            printf("Error in copy object \n" );
        }
    
    ?>
    

    =======================x================================================

提交回复
热议问题