Note that the key and secret are what you noted down after setting up the "Spaces access key" earlier. The region can be inferred from the endpoint URL you noted down earlier. It's the part after the first . in the URL, in my case it is ams3. The endpoint is the same endpoint URL minus the unique name you chose.
Next we need to set up the actual Flysystem adapter to use the S3 client:
Finally, we need to ensure that avatar and attachment thumbnail URLs are prepended with the correct URL. This requires the endpoint URL you noted down earlier, again:
At this point, everything should be working in terms of new uploads. Don't be alarmed if you notice that avatars and thumbnails are missing; if you have existing files, they will need to be moved over manually which we'll go through later.
First, we need to test that the configuration works. Simply go and upload a new avatar. The avatar will now be stored and served remotely!
If you check your DigitalOcean Spaces account now, you should see that new folders have been created containing your new avatar:
Success! 🌟 But we're only half way there!
We now need to add support for the internal_data directory stuff too. Generally, this is attachments and any other stuff that should be "private". Back to config.php and the code to add is very similar:
In the "AWS services" section type "S3" to go to the "S3 Console".
Click "Create bucket".
Choose a bucket name (I have chosen xftest).
Choose a region (I have chosen EU London).
Accept any further default options until the bucket is created.
You now need to go to the "IAM" console.
Click "Add user".
Pick a username (yep, I used xftest again 😉).
Set the access type to "Programmatic".
To set permissions, click the "Attach existing policies directly" tab followed by the "Create policy" button.
IAM and the various policies and permissions can be fairly daunting. We can make it a bit easier, though you may have different requirements. On this page there is a tab called "JSON". Paste the following in there, replacing YOUR-BUCKET-NAME with the bucket name you chose earlier:
Go back to the previous "Add user" page, click the "Refresh" button and search for the policy you just created.
Click "Next", followed by "Create user".
This will give you a key and a secret. Note them down.
Configuring XF to use Amazon S3
We now need to configure XF to use Amazon S3 for file storage. We'll start with what usually goes into the data directory first. This generally includes attachment thumbnails and avatars.
Open your src/config.php file.
We will do this using a closure so that we can reuse the same code and we only have to type it out once:
At this point, everything should be working in terms of new uploads. Don't be alarmed if you notice that avatars and thumbnails are missing; if you have existing files, they will need to be moved over manually which we'll go through later.
First, we need to test that the configuration works. Simply go and upload a new avatar. The avatar will now be stored and served remotely!
If you check your bucket file browser now, you should see that new folders have been created containing your new avatar:
Success! 🌟 But we're only half way there!
We now need to add support for the internal_data directory stuff too. Generally, this is attachments and any other stuff that should be "private". Back to config.php and the code to add is very similar: