A WordPress plugin that automatically uploads images, videos, documents, and any other media added through WordPress' media uploader to S3-compatible remote storage.
This plugin seamlessly integrates with WordPress' native media uploader to automatically sync uploaded files to S3-compatible object storage services. Once configured, all media files are automatically uploaded to your remote storage while maintaining WordPress' standard media library functionality.
- π Automatic Upload: Automatically uploads media files to S3 when added through WordPress media uploader
- π All Media Types: Supports images, videos, documents, and any file type WordPress allows
- π Deduplication: Smart file management using MD5 hashing to avoid duplicate uploads
- ποΈ Reference Counting: Tracks file usage to safely manage deletions
- π S3-Compatible: Works with AWS S3, MinIO, DigitalOcean Spaces, and any S3-compatible storage
- π Transparent URLs: Automatically rewrites attachment URLs to point to remote storage
- ποΈ Automatic Cleanup: Removes files from remote storage when deleted from WordPress
- PHP 7.4 or higher (8.0+ supported)
- WordPress 5.0 or higher
- S3-compatible storage service credentials
Note: Composer is only required for development. End users can install the plugin directly from releases.
- Download the latest release ZIP file from GitHub Releases
- Go to your WordPress admin panel
- Navigate to
PluginsβAdd NewβUpload Plugin - Click
Choose Fileand select the downloaded ZIP file - Click
Install Now - After installation, click
Activate Plugin
- Download the latest release ZIP file from GitHub Releases
- Extract the ZIP file
- Upload the
wordpress-flysystem-s3folder to/wp-content/plugins/directory via FTP or file manager - Go to
PluginsβInstalled Pluginsin WordPress admin - Find "WordPress Flysystem S3" and click
Activate
If you're developing or contributing to the plugin:
cd wp-content/plugins
git clone https://github.com/itsmattius/wordpress-flysystem-s3.git
cd wordpress-flysystem-s3
composer installAfter installation and activation, add the following constants to your wp-config.php file:
// Required S3 Configuration
define('S3_KEY', 'your-access-key');
define('S3_SECRET', 'your-secret-key');
define('S3_REGION', 'us-east-1'); // Your S3 region
define('S3_BUCKET', 'your-bucket-name');
define('S3_ENDPOINT', 'https://s3.amazonaws.com'); // Or your S3-compatible endpoint
// Optional: Specify a root directory within the bucket
define('S3_ROOT', 'wordpress/media'); // Leave undefined for bucket rootNote: The plugin will automatically create the necessary database table upon activation.
define('S3_KEY', 'AKIAIOSFODNN7EXAMPLE');
define('S3_SECRET', 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY');
define('S3_REGION', 'us-east-1');
define('S3_BUCKET', 'my-wordpress-media');
define('S3_ENDPOINT', 'https://s3.amazonaws.com');define('S3_KEY', 'minioadmin');
define('S3_SECRET', 'minioadmin');
define('S3_REGION', 'us-east-1');
define('S3_BUCKET', 'wordpress');
define('S3_ENDPOINT', 'https://minio.example.com');define('S3_KEY', 'your-spaces-key');
define('S3_SECRET', 'your-spaces-secret');
define('S3_REGION', 'nyc3');
define('S3_BUCKET', 'your-space-name');
define('S3_ENDPOINT', 'https://nyc3.digitaloceanspaces.com');The plugin hooks into WordPress' media upload process:
- Upload Detection: Intercepts files when uploaded through WordPress media uploader
- MD5 Hashing: Generates MD5 hash of the file for deduplication
- Remote Upload: Uploads file to S3 storage with organized directory structure (
/ab/cd/abcd1234...) - Database Tracking: Records file mapping in custom database table
- URL Rewriting: Automatically rewrites attachment URLs to point to S3 storage
- Smart Deletion: Handles file deletion with reference counting
The plugin creates a table wp_fs_s3_files with the following structure:
| Column | Type | Description |
|---|---|---|
id |
int(10) | Auto-increment primary key |
local_file |
varchar(512) | Original WordPress file path |
remote_file |
varchar(512) | Full S3 URL |
md5 |
varchar(32) | MD5 hash of the file |
count |
smallint(5) | Reference count for safe deletion |
Once installed and configured, the plugin works automatically:
- Go to
MediaβAdd Newin WordPress admin - Upload your files as usual
- Files are automatically uploaded to S3 in the background
- Media library displays files with S3 URLs
All attachment URLs automatically point to your S3 storage:
// Standard WordPress function
$url = wp_get_attachment_url($attachment_id);
// Returns: https://s3.amazonaws.com/your-bucket/ab/cd/abcd1234ef567890.jpgWhen you delete media from WordPress:
- If the file is used once, it's removed from both WordPress and S3
- If the file has multiple references, the reference count is decremented
- Only when the last reference is removed, the file is deleted from S3
Files are stored in S3 with a hierarchical structure based on MD5 hash:
bucket/
βββ ab/
βββ cd/
βββ abcd1234ef567890.jpg
This structure helps distribute files evenly and improves performance.
- Verify all required S3 constants are defined in
wp-config.php - Check S3 credentials are correct and have proper permissions
- Ensure the S3 bucket exists and is accessible
- Check WordPress debug log for errors
- Verify PHP has write permissions to WordPress upload directory
- Check S3 bucket permissions allow
PutObjectoperation - Ensure the endpoint URL is correct for your S3 provider
- Check for PHP memory limit or timeout issues
Add to wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);Check /wp-content/debug.log for error messages.
- Store S3 credentials securely in
wp-config.php(never commit to version control) - Use IAM credentials with minimal required permissions:
s3:PutObject- Upload filess3:GetObject- Read files (if private)s3:DeleteObject- Delete files
- Consider using environment variables for credentials
- Enable bucket versioning for data protection
- Configure appropriate bucket CORS settings if needed
To contribute to this plugin or run it in development mode:
# Clone the repository
git clone https://github.com/itsmattius/wordpress-flysystem-s3.git
cd wordpress-flysystem-s3
# Install dependencies
composer install
# Configure wp-config.php with test S3 credentials
# Activate the plugin in WordPress- league/flysystem-aws-s3-v3 - Flysystem adapter for AWS S3
This project is licensed under the MIT License - see the LICENSE file for details.
Mehdi Abedi
- Email: abedi1667@gmail.com
Contributions are welcome! Please feel free to submit a Pull Request.
For issues, questions, or contributions, please visit the GitHub repository.
- Initial release
- Automatic media upload to S3
- Support for all media types
- MD5-based deduplication
- Reference counting for safe deletions
- S3-compatible storage support