Skip to content

Instantly share code, notes, and snippets.

@bobmurdoch
Last active January 24, 2025 19:03
Show Gist options
  • Save bobmurdoch/958b2cbe54f35b3ee0f1c6736e7f2676 to your computer and use it in GitHub Desktop.
Save bobmurdoch/958b2cbe54f35b3ee0f1c6736e7f2676 to your computer and use it in GitHub Desktop.
Using Laravel's S3 filesystem driver with Backblaze B2, R2 Cloudflare and possibly others -- Unsupported header 'x-amz-checksum-crc32'

Up until recently it has been fairly simple to make a config/filesystem.php entry for Backblaze B2 and just set the use_path_style_endpoint to true, and set the endpoint based on guides you can find online to connect via their S3 compatible API.

Changes recent to the time of writing this in aws-sdk-php added a x-amz-checksum-crc32 header to write calls, and this header
causes B2 calls to fail. I assume the same is true for Cloudflare R2 but haven't confirmed yet, and possibly other s3 compatible API providers. (Cloudflare mentions it at the top of this page at the time of writing) https://developers.cloudflare.com/r2/examples/aws/aws-sdk-php/

I don't believe custom adapter config cant be set in the filesystem.php config file based on my tests. If I'm wrong, would be great to hear how in a response commment.

So instead I created a custom driver that pulls config from my previously working B2 config entry, makes a new s3 driver with the one required customization. In a service provider's boot function, add

  Storage::extend('custom_b2_driver', function (\Illuminate\Contracts\Foundation\Application $app, $config) {
      $config['request_checksum_calculation'] = 'when_required';
      $config['response_checksum_validation'] = 'when_required';
      return $app->make(\Illuminate\Filesystem\FilesystemManager::class)->createS3Driver($config);
  });

and in the config/filesystem.php file change your B2 entry to use this new driver.

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