Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thomaskanzig/0294864c9931031d9a01969a27046e32 to your computer and use it in GitHub Desktop.

Select an option

Save thomaskanzig/0294864c9931031d9a01969a27046e32 to your computer and use it in GitHub Desktop.

Revisions

  1. thomaskanzig revised this gist Mar 31, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get-list-and-delete-objects-from-aws-s3-bucket.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # List object from AWS S3 Bucket
    # Get, list and delete objects from AWS S3 Bucket

    As requirement, install the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) library to connect AWS S3.
    First of all you need to connect to your AWS S3:
  2. thomaskanzig renamed this gist Mar 31, 2023. 1 changed file with 27 additions and 2 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # List object from AWS S3 Bucket

    As requirement, install the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) library to connect AWS S3.

    First of all you need to connect to your AWS S3:


    ```bash
    @@ -23,6 +23,12 @@ $config =

    $client = new \Aws\S3\S3Client($config);

    ```


    #### List objects:

    ```bash
    $result = $client->listObjects([
    'Bucket' => 'bucket-name',
    'Prefix' => 'sub/directory/'
    @@ -36,4 +42,23 @@ foreach ($result['Contents'] as $key => $object) {

    echo $object['Key'] . "<br>";
    }
    ```
    ```
    #### Get object:
    ```bash
    $object = $client->getObject(array(
    'Bucket' => 'bucket-name',
    'Key' => 'sub/directory/image.jpg'
    ));
    ```
    #### Delete object:
    ```bash
    $client->deleteObject([
    'Bucket' => 'bucket-name',
    'Key' => 'sub/directory/image.jpg'
    ]);
    ```
  3. thomaskanzig revised this gist Mar 28, 2023. No changes.
  4. thomaskanzig created this gist Mar 28, 2023.
    39 changes: 39 additions & 0 deletions list-object-from-aws-s3-bucket.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    # List object from AWS S3 Bucket

    As requirement, install the [AWS SDK for PHP](https://github.com/aws/aws-sdk-php) library to connect AWS S3.



    ```bash
    require 'vendor/autoload.php';
    use Aws\S3\S3Client;
    use Aws\Exception\AwsException;

    $config =
    [
    'version' => 'latest',
    'region' => '',
    'endpoint' => '[cluster-url]',
    'credentials' =>
    [
    'key' => '[access-key]',
    'secret' => '[secret-key]',
    ],
    ];

    $client = new \Aws\S3\S3Client($config);

    $result = $client->listObjects([
    'Bucket' => 'bucket-name',
    'Prefix' => 'sub/directory/'
    ]);

    foreach ($result['Contents'] as $key => $object) {
    // Is the value of prefix.
    if (0 === $key) {
    continue;
    }

    echo $object['Key'] . "<br>";
    }
    ```