What is Linode Object storage?
Linode Object Storage is a highly available S3 compatible object storage.
It is used to manage unstructured data such as images, videos, etc.
Setting up Object Storage in Linode
- Go to Linode cloud console.
From the Object storage dashboard, go to Access key tab and select create access key.
Give it a name, and give it Read/Write access for the bucket created in the previous step.
It will show you the access and secret keys, copy and save it securely.
Configuring Laravel application
Since Linode Object Storage is a S3 compatible, we can use the S3 driver in Laravel for managing files.
-
To use the S3 driver we need to install the
flysystem
package in Laravel. Use the following command to install the package
composer require league/flysystem-aws-s3-v3 "^3.0"
-
We need to create some environment variables in the
.env
file of Laravel application as follows
LINODE_KEY="your-linode-access-key" LINODE_SECRET="your-linode-access-secret" LINODE_ENDPOINT="https://ap-south-1.linodeobjects.com" LINODE_REGION="ap-south-1" LINODE_BUCKET="dev-to" LINODE_BUCKET_URL="https://dev-to.ap-south-1.linodeobjects.com/"
You can get the bucket url from the details of the bucket in linode cloud console.
-
Go to
config/filesystems.php
config file and add the following in thedisks
array.
<?php 'disks' => [ ... 'linode' => [ 'driver' => 's3', 'key' => env('LINODE_KEY'), 'secret' => env('LINODE_SECRET'), 'endpoint' => env('LINODE_ENDPOINT'), 'region' => env('LINODE_REGION'), 'bucket' => env('LINODE_BUCKET'), 'visibility' => 'public', ], ... ]
-
Make sure you have
linode
set as the default file system disk in the.env
file. Otherwise you have to specify each time you call a method.
FILESYSTEM_DISK=linode
Storing files in Linode
Now you can use the available methods in Laravel to manage the files in Linode Object Storage.
For example,
use Illuminate\Support\Facades\Storage;
Storage::disk('linode')->put('avatars/1', $content);
$contents = Storage::get('avatars/user.jpg'); // No need to specify disk name if the default is set to 'linode'
Top comments (0)