DEV Community

Md. Abdur rahman
Md. Abdur rahman

Posted on • Updated on • Originally published at dev.to

Wasabi Cloud Storage with Laravel 9

Wasabi is a cloud object storage that is compatible with Amazon S3. It can be integrated with AWS, Google Cloud or Microsoft Azure solutions, using the same protocol and tools. Wasabi is a value-oriented, high-performance, low-latency, and high-availability cloud object storage offering.


Step - 1: Set up your laravel app enviroment (.env file) with your wasabi credentials like this.



WAS_ACCESS_KEY_ID=4I349UKY85N1FR3D4BBW2
WAS_SECRET_ACCESS_KEY=Z1FOT1cWCuH7zDtEMv6pGZ9SmA2yspno7G
WAS_DEFAULT_REGION=ap-northeast-1
WAS_BUCKET=mybucket
WAS_URL=https://s3.ap-northeast-1.wasabisys.com


Enter fullscreen mode Exit fullscreen mode

Step - 2: The S3 driver configuration information is located in your config/filesystems.php configuration file. This file contains an example configuration array for an S3 driver. You are free to modify this array with your own S3 configuration and credentials.

So, add your wasabi driver configuration information to config/filesystems.php



<?php

return [

    'default' => env('FILESYSTEM_DRIVER', 'local'),

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],


        'wasabi' => [
            'driver' => 's3',
            'key' => env('WAS_ACCESS_KEY_ID'),
            'secret' => env('WAS_SECRET_ACCESS_KEY'),
            'region' => env('WAS_DEFAULT_REGION'),
            'bucket' => env('WAS_BUCKET'),
            'endpoint' => 'https://s3.wasabisys.com'
        ],

    ],

];


Enter fullscreen mode Exit fullscreen mode

Step - 3: Before using the S3 driver, you will need to install the Flysystem S3 package via the Composer package manager:



composer require league/flysystem-aws-s3-v3


Enter fullscreen mode Exit fullscreen mode
  • Remember to give permission at your bucket access control.
    'object write and read access' should have to enable before upload any file. like this -

  • give your bucket access control from bucket settings


Step - 4: Finally, you can upload your media file to your bucket of wasabi cloud storage using this -



\Illuminate\Support\Facades\Storage::disk('wasabi')>put($file, $fileContents, 'public');


Enter fullscreen mode Exit fullscreen mode

check if file not exist and upload at your bucket-



if (!\Illuminate\Support\Facades\Storage::disk('wasabi')->exists($fileLocationInsideYourBucket)) {
    \Illuminate\Support\Facades\Storage::disk('wasabi')->put($file, $fileContents, 'public');
 }


Enter fullscreen mode Exit fullscreen mode


You can also follow up the official guidance Wasabi Laravel to learn more.

Top comments (1)

Collapse
 
abul_hossain_8fdc38c71da1 profile image
abul hossain

Thank you bhai