简体   繁体   English

S3-需要从AWS下载特定图像并以zip下载

[英]S3 - need to download particular images from aws and download them in zip

I need to download images from AWS bucket into a local directory and zip download them. 我需要将图像从AWS存储桶下载到本地目录,然后将其zip下载。

I have tried my code, but can't figure out how will I copy the images into my local directory. 我已经尝试了我的代码,但无法弄清楚如何将图像复制到本地目录中。

here is my function : 这是我的功能:

     public function commomUpload($contentId,$prop_id)
 {
    $client = S3Client::factory(array(
                'key' => 'my key',
                'secret' => '----secret-----',
            ));
    $documentFolderName = 'cms_photos';
    $docbucket = "propertiesphotos/$prop_id/$documentFolderName";
            $data = $this->Photo->find('all',array('conditions'=>array('Photo.content_id'=>$contentId)));

    //pr($data);die;
    $split_point = '/';

    foreach($data as $row){
        $string = $row['Photo']['aws_link'];

        $result = array_map('strrev', explode($split_point, strrev($string)));
        $imageName = $result[0];
        $result = $client->getObject(array(
            'Bucket' => $docbucket,
            'Key'    => $imageName
        ));
        $uploads_dir = '/img/uploads/';
        if (!copy($result, $uploads_dir)) {
            echo "failed to copy $result...\n";
        }
        //move_uploaded_file($imageName, "$uploads_dir/$imageName");
    }
}

Dont complicate things. 不要使事情复杂化。 There exists a very simple tools called s3cmd. 存在一个非常简单的工具,称为s3cmd。 Install it in any platforms. 在任何平台上安装它。 Click here to know more. 点击这里了解更多。 Once you download the images from the s3,use can either use gzip or zip it using just a bash script. 从s3下载图像后,use可以使用gzip或仅使用bash脚本将其压缩。 Dont forget to configure your s3cmd. 不要忘记配置您的s3cmd。 You need to have AWS access key and secret key with you. 您需要随身携带AWS访问密钥和秘密密钥。

您可以使用Amazon S3 cakephp插件https://github.com/fullybaked/CakeS3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM