Skip to content

Instantly share code, notes, and snippets.

@Nembie
Last active January 30, 2024 14:59
Show Gist options
  • Save Nembie/7269c634e44e857f5b289eeedcacf845 to your computer and use it in GitHub Desktop.
Save Nembie/7269c634e44e857f5b289eeedcacf845 to your computer and use it in GitHub Desktop.
🪣 How to Use Backblaze S3 Bucket in Laravel

🪣 How to Use Backblaze S3 Bucket in Laravel

⚠️ If you're new to Backblaze, use this guide before proceeding.

1. :dependabot: Install Necessary Dependencies

$ composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies

2. 🛠️ Set Up Your .env File as Follows

AWS_ACCESS_KEY_ID=YOUR_APPLICATION_KEY_ID # ex. 0050cXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=YOUR_APPLICATION_ACCESS_KEY_ID # K005XXXXXXXXXXXXXXXXX
AWS_DEFAULT_REGION=BUCKET_REGION # ex. us-east-001
AWS_BUCKET=YOUR_BUCKET_NAME # ex. testbackblaze
AWS_ENDPOINT=https://s3.BUCKET_REGION.backblazeb2.com # ex. https://s3.us-east-001.backblazeb2.com

3. 🧰 Test Command (Optional)

Create a command:

$ php artisan make:command TestS3

Copy and paste the following content into the created file:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class TestS3 extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test-s3';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test S3 connection with Backblaze';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $s3 = Storage::disk('s3');
        $s3->put('test.txt', 'Hello World');

        if ($s3->exists('test.txt')) {
            $this->info('Everything is ok');
        } else {
            $this->error('Something went wrong');
        }
    }
}

Run the command

php artisan app:test-s3

That's it! ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment