eriktobben's avatar

Use Backblaze B2 with Storage instead of S3

Hi,

I have successfully connected to Backblaze via the S3 adapter of the filesystem and can retrieve files, but I'm trying to generate a temporary URL, but the returned URL includes the Amazon domain: https://BUCKETNAME.s3.eu-central-003.amazonaws.com/...

In my .env I have set the following:

B2_DEFAULT_REGION=eu-central-003
B2_BUCKET=BUCKETNAME
B2_URL=s3.eu-central-003.backblazeb2.com

According to the Backblaze S3 API documentation it does support signed URLs. Does anyone know how to change the amazonaws.com domain to backblazeb2.com?

0 likes
4 replies
LaryAI's avatar
Level 58

To use Backblaze B2 with Laravel's Storage facade instead of Amazon S3, you need to configure the filesystems.php config file correctly. Since Backblaze B2 is compatible with the S3 API, you can use the S3 driver but with Backblaze B2's endpoints.

Here's how you can configure it:

  1. Update your .env file with the necessary Backblaze B2 credentials and endpoints:
B3_KEY=your_backblaze_key
B3_SECRET=your_backblaze_secret
B3_BUCKET=your_bucket_name
B3_ENDPOINT=s3.eu-central-003.backblazeb2.com
B3_REGION=eu-central-003
  1. Modify the config/filesystems.php to include a new disk configuration for Backblaze B2:
'disks' => [

    // ...

    'backblaze' => [
        'driver' => 's3',
        'key' => env('B3_KEY'),
        'secret' => env('B3_SECRET'),
        'region' => env('B3_REGION'),
        'bucket' => env('B3_BUCKET'),
        'endpoint' => env('B3_ENDPOINT'),
        'url' => env('B3_URL'),
        'use_path_style_endpoint' => true,
    ],

    // ...

],
  1. When generating a temporary URL, make sure to use the backblaze disk you've just configured:
$url = Storage::disk('backblaze')->temporaryUrl(
    'filename.txt', now()->addMinutes(5)
);

This should generate a temporary URL with the correct domain for Backblaze B2.

If you're still seeing the Amazon domain in your URLs, double-check that you're using the correct disk when generating the URL and that the B3_ENDPOINT and B3_URL in your .env file are set to the Backblaze B2 endpoint and not the Amazon S3 endpoint.

Remember to clear the config cache after making changes to your .env file or the config/filesystems.php file:

php artisan config:clear

This should resolve the issue and allow you to generate temporary URLs with the correct Backblaze B2 domain.

eriktobben's avatar

When trying to set B2_ENDPOINT I get the following error: Custom endpoint s3.eu-central-003.backblazeb2.com was not a valid URI

nexxai's avatar
nexxai
Best Answer
Level 37

@eriktobben Right because the URL requires the scheme. Add https:// to the beginning

1 like

Please or to participate in this conversation.