如何通过Zend_Service_Amazon_S3访问Amazon s3专用存储桶对象

问题描述:

我已经在amazon s3上创建了一个存储桶,并将一些图像保存在该存储桶的文件夹中。所有图像都是私有的,我正在使用Zend的Zend_Service_Amazon_S3类。

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.

谢谢,
Pravin

Thanks, Pravin

您可以通过创建私有网址来完成此任务,就像这样

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}";
}

现在使用此URL进行访问。

now use this url to get access.