Summary
Replace the bundled AWS SDK (located in src/aws/) with a lightweight, custom S3-compatible REST service using Guzzle HTTP client. This will significantly reduce installation size and complexity while maintaining full compatibility with S3-compatible storage providers.
Background
The project currently includes a full copy of the AWS SDK directly in src/aws/ (not as a Composer dependency). Despite the SDK's size (~5,000 files), only a handful of S3 operations are actually used:
| Operation |
Purpose |
putObject |
Upload files to S3 |
getObject |
Download/stream files |
headObject |
Get file metadata (size, content-type) |
deleteObject |
Delete files |
doesObjectExist |
Check file existence |
listObjectsV2 |
List files (orphaned file scan) |
headBucket |
Test connection |
createPresignedRequest |
Generate presigned URLs |
Additionally, FileController uses the S3Client directly for streaming files with Range header support (HTTP 206 partial content) and video preview streaming.
Proposed Solution
Create a custom S3Service class that implements all required S3 operations using simple REST API calls via Guzzle HTTP client. This service will:
- Handle all authentication using AWS Signature V4
- Support all S3-compatible providers (AWS S3, Digital Ocean Spaces, MinIO, etc.)
- Provide the same functionality as the current AWS SDK usage
- Add support for Range requests for video/file streaming
Implementation Plan
Phase 1: Create Custom S3 Service
Create src/Phuppi/Storage/S3Service.php with the following interface:
class S3Service
{
public function putObject(string $key, string $filePath): bool;
public function getObject(string $key): StreamInterface;
public function headObject(string $key): array;
public function deleteObject(string $key): bool;
public function doesObjectExist(string $key): bool;
public function listObjectsV2(string $prefix): array;
public function headBucket(): bool;
public function createPresignedUrl(string $method, string $key, int $expiresIn): string;
}
Key implementation details:
- Use
guzzlehttp/guzzle for HTTP requests
- Use
guzzlehttp/psr7 for PSR-7 stream implementation
- Implement AWS Signature V4 signing for authentication
- Support Range headers for partial content streaming
Phase 2: Update S3Storage Wrapper
Update src/Phuppi/Storage/S3Storage.php:
- Replace
Aws\S3\S3Client property with S3Service
- Update all method implementations to delegate to
S3Service
- Maintain the same public interface for backward compatibility
Phase 3: Handle Direct S3Client Usage
Refactor src/Phuppi/Controllers/FileController.php:
- Add methods to
S3Service for Range request streaming
- Update
S3Storage to expose these capabilities
- Remove direct
$storage->getS3Client() calls
Also update src/Phuppi/Controllers/SettingsController.php for orphaned file scanning.
Phase 4: Remove AWS SDK
- Delete entire
src/aws/ directory
- Remove any AWS-related imports and references
Implementation Checklist
Benefits
- Reduced Installation Size - Remove ~5,000 files from the bundle
- Faster Installation - No need to download/install massive AWS SDK
- Easier Maintenance - Single custom service vs. massive SDK
- Better Performance - Lightweight HTTP calls only
- Full S3 Compatibility - Works with AWS S3, Digital Ocean Spaces, MinIO, etc.
Dependencies
The new implementation will require:
guzzlehttp/guzzle - HTTP client (already available in project)
guzzlehttp/psr7 - PSR-7 stream implementation (for file streaming)
No additional Composer dependencies required.
Files to Modify
src/Phuppi/Storage/S3Storage.php - Update to use new S3Service
src/Phuppi/Controllers/FileController.php - Remove direct S3Client usage
src/Phuppi/Controllers/SettingsController.php - Update orphaned file scanning
src/aws/ - Delete entire directory
Files to Create
src/Phuppi/Storage/S3Service.php - New lightweight S3 REST client
Summary
Replace the bundled AWS SDK (located in
src/aws/) with a lightweight, custom S3-compatible REST service using Guzzle HTTP client. This will significantly reduce installation size and complexity while maintaining full compatibility with S3-compatible storage providers.Background
The project currently includes a full copy of the AWS SDK directly in
src/aws/(not as a Composer dependency). Despite the SDK's size (~5,000 files), only a handful of S3 operations are actually used:putObjectgetObjectheadObjectdeleteObjectdoesObjectExistlistObjectsV2headBucketcreatePresignedRequestAdditionally,
FileControlleruses the S3Client directly for streaming files with Range header support (HTTP 206 partial content) and video preview streaming.Proposed Solution
Create a custom
S3Serviceclass that implements all required S3 operations using simple REST API calls via Guzzle HTTP client. This service will:Implementation Plan
Phase 1: Create Custom S3 Service
Create
src/Phuppi/Storage/S3Service.phpwith the following interface:Key implementation details:
guzzlehttp/guzzlefor HTTP requestsguzzlehttp/psr7for PSR-7 stream implementationPhase 2: Update S3Storage Wrapper
Update
src/Phuppi/Storage/S3Storage.php:Aws\S3\S3Clientproperty withS3ServiceS3ServicePhase 3: Handle Direct S3Client Usage
Refactor
src/Phuppi/Controllers/FileController.php:S3Servicefor Range request streamingS3Storageto expose these capabilities$storage->getS3Client()callsAlso update
src/Phuppi/Controllers/SettingsController.phpfor orphaned file scanning.Phase 4: Remove AWS SDK
src/aws/directoryImplementation Checklist
src/Phuppi/Storage/S3Service.phpwith Guzzle HTTP clientS3Storageto useS3ServiceFileControllerto remove direct S3Client usageSettingsControllerorphaned file scanningsrc/aws/directoryBenefits
Dependencies
The new implementation will require:
guzzlehttp/guzzle- HTTP client (already available in project)guzzlehttp/psr7- PSR-7 stream implementation (for file streaming)No additional Composer dependencies required.
Files to Modify
src/Phuppi/Storage/S3Storage.php- Update to use new S3Servicesrc/Phuppi/Controllers/FileController.php- Remove direct S3Client usagesrc/Phuppi/Controllers/SettingsController.php- Update orphaned file scanningsrc/aws/- Delete entire directoryFiles to Create
src/Phuppi/Storage/S3Service.php- New lightweight S3 REST client