Search
 
SCRIPT & CODE EXAMPLE
 

PHP

aws s3 laravel package

composer require league/flysystem-aws-s3-v3
Comment

get s3 object from aws in laravel

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

laravel upload file to aws s3

use IlluminateSupportFacadesStorage;

$file_upload = Storage::disk('s3')->put('/folder_name', $request->file);

//must have in .env
AWS_ACCESS_KEY_ID=access_key
AWS_SECRET_ACCESS_KEY=secret_key
AWS_DEFAULT_REGION=region
AWS_BUCKET=bucket_name
AWS_USE_PATH_STYLE_ENDPOINT=false
Comment

PREVIOUS NEXT
Code Example
Php :: get header respnse code php curl 
Php :: How to pass JavaScript variables to PHP? 
Php :: laravel curl request 
Php :: Laravel - Comparison betweeon two column values - whereColumn 
Php :: string to int php 
Php :: malformed utf-8 characters possibly incorrectly encoded php 
Php :: continue php 
Php :: php mysqli connect err0r 
Php :: php json_decode without quotes 
Php :: laravel websockets onmessage 
Php :: php clone object 
Php :: laravel collection chunk 
Php :: laravel route group name 
Php :: db::statement in laravel 
Php :: php ternary operator 
Php :: add shortcode in short description 
Php :: laravel 8 change password 
Php :: strval in php 
Php :: php abs() 
Php :: php curl example 
Php :: check value falls between in two range in php 
Php :: php convert string to url 
Php :: datetime php 
Php :: laravel pagination with get parameters 
Php :: In PackageManifest.php line 122: 
Php :: laravel how to ignore fields case insensitive 
Php :: wordpress post revisions config 
Php :: add hour minute in datetime in php 
Php :: php remove anchor tag from string 
Php :: php delete json object from a collection object 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =