How to access Amazon s3 private bucket object through Zend_Service_Amazon_S3

穿精又带淫゛_ 提交于 2019-12-30 03:33:08

问题


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 Zend.

Please let me know how can I access the private images.

Thanks, Pravin


回答1:


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.




回答2:


Try this: It will return the binary data for the file stored on the Amazon S3 Bucket.

require_once 'Zend/Service/Amazon/S3.php';
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);
echo $s3->getObject("my-own-bucket/myobject");

Documentation is here: http://framework.zend.com/manual/de/zend.service.amazon.s3.html
This is example #1



来源:https://stackoverflow.com/questions/8799842/how-to-access-amazon-s3-private-bucket-object-through-zend-service-amazon-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!