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:
- Update your
.envfile 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
- Modify the
config/filesystems.phpto 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,
],
// ...
],
- When generating a temporary URL, make sure to use the
backblazedisk 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.