简体   繁体   中英

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.

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. 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. Dont forget to configure your s3cmd. You need to have AWS access key and secret key with you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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