Using UpCloud S3 for Laravel Object Storage

laravel

Simon Bennett 12th January 2021

We were excited when we heard in November 2020 that UpCloud added there own object storage system, we have added it as one of the storage locations at SnapShooter.

UpCloud storage is 100% compatible with AWS S3 making connecting to laravel a straightforward process.

Configuring Laravel With UpCloud

We will make use of the existing laravel setup for connecting storage.

Checking Laravel S3 Dependencies

Make sure you already have the FlySystem S3 adapter installed in your projects compose dependencies.

composer require league/flysystem-aws-s3-v3

(Note: with Laravel 8 I found I needed to install version 1.0.29 to get it to work)

Setting up ENV

Add the following to your .env file; you will need to extract this data from your UpCloud

UPCLOUD_KEY=[KEY] 
UPCLOUD_SECRET=[SECRET] 
UPCLOUD_ENDPOINT=https://[public endpoint].[region].upcloudobjects.com
UPCLOUD_REGION=[REGION] 
UPCLOUD_BUCKET=[YOURBUCKET]

Public Endpoint Config

Editing the Config

config/filesystems.php

I prefer to have new providers listed as its own in the storage. Find the disks array and add the following.

'upcloud' => [
    'driver' => 's3',
    'key' => env('UPCLOUD_KEY'),
    'secret' => env('UPCLOUD_SECRET'),
    'endpoint' => env('UPCLOUD_ENDPOINT'),
    'region' => env('UPCLOUD_REGION'),
    'bucket' => env('UPCLOUD_BUCKET'),
],

Testing Uploads

Storage::disk('upcloud')->put('test.html', 'Hello World');

You should see the file uploaded to your UpCloud Bucket.

You could edit the default driver in laravel to now be Laravel

If you want files to be public you can edit this in UpCloud.

Get Started Now

Get started with SnapShooter for free!
Backup one droplet, volume or mysql database