Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get image object in s3 bucket

use AwsS3S3Client; 
        // first connection with aws
        $s3client = S3Client::factory ( [ 
            'credentials' => [ 
                    'key' => 'Your aws key',
                    'secret' => 'Your aws secret key' 
                ],
                'region' => 'eu-west-1',
                'version' => '2006-03-01' 
            ] );

       

try {
    $image_name_array=[];
    $image_object=[];
    // Get List Of S3  Object in specified folder name 
    $contents = $s3client->listObjects([
        'Bucket' => 'bucket', // bucket name
        'Prefix' => 'public/uploads' // folder name
         
    ]);
    
    foreach ($contents['Contents'] as $content) {
        // push key of s3 object in array
        array_push($image_name_array,$content['Key']);
        // print_r($content['Key']);
    }
    
    foreach($image_name_array as $image_key){
    // get the image file from given key 
        $result = $s3client->getObject([
        'Bucket' => 'chemco',
        'Key'    =>  $image_key,
    ]);
       header("Content-Type: {$result['ContentType']}");
       // store the image file in array
       array_push($image_object,$result['Body']);
    }
     
     // You can see the image 
   
     foreach($image_object as $key=>$obj){
        if($key==1){
            echo $obj;
            return $obj;
        }
        
    }
} catch (Exception $exception) {
    echo "Failed to list objects in chemco with error: " . $exception->getMessage();
    exit("Please fix error with listing objects before continuing.");
}
Comment

get image from s3 bucket javascript

let params = { Bucket: config.bucket, Key: req.params.imageId };
s3.getObject(params, function(err, data) {
    res.writeHead(200, {'Content-Type': 'image/jpeg'});
    res.write(data.Body, 'binary');
    res.end(null, 'binary');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord js embeded message hyperlink 
Javascript :: javascript pure ajax 
Javascript :: node express params 
Javascript :: null + undefined 
Javascript :: how to stop canvas resizing from resizing images 
Javascript :: expo font 
Javascript :: convert array of javascript into string with comma 
Javascript :: how to import json data from a local file 
Javascript :: popper.js and jquery 
Javascript :: javascript print to pdf 
Javascript :: Making promises 
Javascript :: string.replace javascript 
Javascript :: intersection observer api 
Javascript :: load url onclick javascript 
Javascript :: random color js 
Javascript :: vuex do not mutate vuex store state outside mutation handlers. nuxt 
Javascript :: cypress run specific test 
Javascript :: Send Email sgMail 
Javascript :: Get rid of white space around Angular Material modal dialog 
Javascript :: data fetch with axios 
Javascript :: js match regex 
Javascript :: how to pass headers in axios 
Javascript :: You provided a `value` prop to a form field without an `onChange` handler 
Javascript :: jquery find and replace text 
Javascript :: how to use the foreach method in javascript 
Javascript :: angular subscribe on value change 
Javascript :: function prototype in javascript 
Javascript :: check if the difference between two dates is more than 1 month in javascript 
Javascript :: arrow function = breakdown steps 
Javascript :: react native map 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =