- Print
- DarkLight
Use the AWS SDK for PHP with Backblaze B2
- Print
- DarkLight
You can take advantage of Backblaze B2 Cloud Storage using the AWS SDK for PHP alongside the Backblaze S3-Compatible API.
Pre-Signed URLs that are generated with the PHP SDK are not currently compatible with Backblaze B2.
When you create a Backblaze B2 bucket, select the Allow List All Bucket Names checkbox. This option is required for the List Buckets operation). If you did not select this when you created your application key, you must create a new application key with this permission enabled.
This example shows how you create a bucket using the AWS SDK for PHP with a profile named b2
in the ~/.aws/credentials
file.
// Include the SDK using the Composer autoloader
require '<path for>/vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate the S3 client using your B2profile
$s3Client = S3Client::factory(array(
'endpoint' => 'https://s3.us-west-002.backblazeb2.com',
'profile' => 'b2',
'region' => 'us-west-002',
'version' => 'latest',
));
//Sample to create a bucket
$s3Client->createBucket(array('Bucket' => '<bucket-name>'));
?>
The S3-Compatible API allows 1000’s of integrations to natively work with Backblaze B2. If you are new to the S3-Compatible API, click here. If you have issues using this SDK with Backblaze B2, let us know by emailing us at [email protected].