Skip to content

Use S3 with DigitalOcean

Pixel Devs edited this page Nov 23, 2021 · 4 revisions

These are the two steps you need to take to get S3 to work with Digital Ocean Spaces.

ADD THIS FILE TO mu-plugins folder in wp-content

/**
* Plugin Name: S3 Uploads DigitalOcean Helper
* Plugin URI: https://www.pixeldevs.io
* Description: Helper file to get DigitalOcean Spaces working with S3 Uploads
* Version: 1.0
* Author: PixelDevs
* Author URI: https://www.pixeldevs.io
**/

// Filter S3 Uploads params.
add_filter( 's3_uploads_s3_client_params', function ( $params ) {
	if ( defined( 'S3_UPLOADS_ENDPOINT' ) ) {
		$params['endpoint'] = S3_UPLOADS_ENDPOINT;
		$params['use_path_style_endpoint'] = true;
		$params['debug'] = false; // Set to true if uploads are failing.
	}
	return $params;
}, 5, 1 );```

## ADD THIS FILE TO mu-plugins folder in wp-content
```define( 'S3_UPLOADS_BUCKET', 'aaaccdn' );
define( 'S3_UPLOADS_REGION', 'sfo3' ); // the s3 bucket region (excluding the rest of the URL)

// You can set key and secret directly:
// THESE ARE YOUR SPACES ACCESS KEYS IN DIGITAL OCEAN | API > SPACES ACCESS KEYS
define( 'S3_UPLOADS_KEY', 'itsTheSmallerOne' );
define( 'S3_UPLOADS_SECRET', 'ItsTheLargerOne' );

// Or if using IAM instance profiles, you can use the instance's credentials:
define( 'S3_UPLOADS_USE_INSTANCE_PROFILE', true );

define('S3_UPLOADS_BUCKET_URL', 'https://aaaccdn.sfo3.digitaloceanspaces.com');
define('S3_UPLOADS_ENDPOINT', 'https://sfo3.digitaloceanspaces.com');```
Clone this wiki locally