How to access Amazon s3 private bucket object through Zend_Service_Amazon_S3

后端 未结 2 1174
孤街浪徒
孤街浪徒 2021-01-01 06:50

I have created a bucket on the amazon s3 and I kept some images in this bucket inside a folder. All the images are private and I am using Zend_Service_Amazon_S3 class of Zen

2条回答
  •  滥情空心
    2021-01-01 07:27

    You can do this task by making private url Like this

    public function get_s3_signed_url($bucket, $resource, $AWS_S3_KEY, $AWS_s3_secret_key, $expire_seconds) {
         $expires = time()+$expire_seconds;
         // S3 Signed URL creation
         $string_to_sign = "GET\n\n\n{$expires}\n/".str_replace(".s3.amazonAWS.com","", $bucket)."/$resource";
         $signature = urlencode(base64_encode((hash_hmac("sha1", utf8_encode($string_to_sign), $AWS_s3_secret_key, TRUE))));
    
         $authentication_params = "AWSAccessKeyId=".$AWS_S3_KEY;
         $authentication_params.= "&Expires={$expires}";
         $authentication_params.= "&Signature={$signature}";
         return $link = "http://s3.amazonAWS.com/{$bucket}/{$resource}?{$authentication_params}";
    }
    

    now use this url to get access.

提交回复
热议问题