Skip to content

S3 Sample Application

Build a REST app that performs S3 object-storage operations through an S3DemoController. You use Winter Boot for the application runtime and the Winter S3 module from Winter Modules for storage access. You test the whole flow locally with MinIO, an S3-compatible object storage server.

You need PHP 8.5 or later with the swoole and pcntl extensions. You also need Docker to run MinIO.

Start MinIO before you run the app:

Terminal window
docker run -d -p 30900:9000 -p 30901:9001 --name minio \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=minioadmin" \
quay.io/minio/minio server /data --console-address ":9001"

MinIO listens on http://localhost:30900, and its console is at http://localhost:30901.

The sample uses this layout:

s3/
├── bin/
│ └── application.php # Application entry point
├── config/
│ ├── application.yml # Winter Boot application config
│ └── s3-config.yml # S3 connections config
├── src/
│ ├── S3SampleApplication.php # Main application class
│ └── controller/
│ └── S3DemoController.php # S3 operations controller
└── composer.json # Dependencies

Require the framework and the modules package:

Terminal window
composer require suvera/winter-boot suvera/winter-modules

Switch between the source files. Each tab shows the exact file from the sample.

The single entry point. It points Winter Boot at the config directory and at the sample namespace.

<?php
namespace dev\example;
use dev\winterframework\stereotype\WinterBootApplication;
#[WinterBootApplication(
configDirectory: [__DIR__ . "/../config"],
scanNamespaces: [
['dev\\example', __DIR__ . '']
]
)]
class S3SampleApplication {
public static function main(): void {
$winterApp = new \dev\winterframework\core\app\WinterWebSwooleApplication();
$winterApp->run(self::class);
}
}

Switch between the two config files. application.yml enables the module, and s3-config.yml defines the primary connection to MinIO.

The full sample file registers S3Module and sets the server and app identity:

server:
port: 8080
address: 0.0.0.0
context-path: /
winter:
application:
name: S3 Sample Application
id: s3-sample-app
version: 1.0.0
modules:
- module: dev\winterframework\s3\S3Module
enabled: true
configFile: s3-config.yml

See Configuration for every application.yml key.

Start the app, then call the endpoints to create a bucket, upload an object, and read it back.

1. Start the application:

Terminal window
composer install
php bin/application.php

2. Create a bucket:

Terminal window
curl -X POST "http://localhost:8080/s3demo/bucket/my-test-bucket"

3. Upload an object:

Terminal window
curl -X POST "http://localhost:8080/s3demo/object?bucket=my-test-bucket&key=test-file.txt&content=Hello%20World"

4. List objects:

Terminal window
curl "http://localhost:8080/s3demo/objects?bucket=my-test-bucket"

5. Download the object:

Terminal window
curl "http://localhost:8080/s3demo/object?bucket=my-test-bucket&key=test-file.txt"

6. Run the complete demo:

Terminal window
curl "http://localhost:8080/s3demo/demo"

The demo creates its own bucket, runs create, upload, head, download, list, and delete in sequence, and returns one status entry per operation.

  • Read the S3 module for the full S3Template API and IAM-role setup.
  • Browse all Libraries when you need Kafka, SQS, Redis, or Doctrine in the same app.